Androidvisual studio控件 中怎样实现控件相对位置定位

android动态设置控件位置_中华文本库
Android 代码中动态设置图片的大小(自动缩放),位置项目中需要用到在代码中动态调整图片的位置和设置图片大小,能自动缩放图片,用 ImageView 控件,具体做法如下: 1、...
基于Android的位置共享应用程序_张嘉杰_计算机软件及应用_IT/计算机_专业资料。关于安卓平台设计的专业文章网络与通信 基于 Android 的位置共享应用程序张嘉杰 摘 要: ...
居中在 VIEW 的下部位置 FIT_START/fitStart 把图片按比例扩大/缩小到 VIEW 的...Android:ellipsize 设置当文字过长时,该控件如何显示,有如下属性 start 省略号...
安卓手机模拟地点方法花几百块上千块买了安卓智能手机, 不要只是用来发微博聊 ...信号定位手机所处的位置,所以如果没有拆 除 sim 卡的话,有可能导致修改 GPS ...
Android手机照片中地址信息添加技术_计算机软件及应用_IT/计算机_专业资料。文章编号: 1009 - 2552 ( 2014 ) 04 - 0027 - 03 中图分类号: TP391. 41 文献标...
安卓手机,华为手机,修改google位置服务_计算机软件及应用_IT/计算机_专业资料。以前用的手机是华为的c8500,刷了google原生系统后,觉得安卓手机还是用原版的最好。一...
靠右等位置就可以通过该属性设置.以 button 为例, android:layout_gravity=&right&则 button 靠右 android:textSize 指定控件当中字体的大小 android:background ...
android:layout_height=&45dip&& &/ImageButton&&! -- 景点位置查询按钮 --...} // 若在气球上按下则设置当前气球为自己, // 且当前状态为在气球上 if(...
android位置服务与地图_计算机软件及应用_IT/计算机_专业资料。android位置服务,地图第八章 位置服务与 地图应用 庞大的计算机系统(本地网络)可以为位于全世 界任何...
Android中自定义Activity和Dialog的位置大小背景和透明度等_IT/计算机_专业资料。...1. &?xml version=&1.0& encoding=&utf-8&?& &resources& &!-- 设置...android studio 控件常用属性_百度文库
您的浏览器Javascript被禁用,需开启后体验完整功能,
享专业文档下载特权
&赠共享文档下载特权
&10W篇文档免费专享
&每天抽奖多种福利
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
android studio 控件常用属性
&&有了控件属性再也不用操心排图了
阅读已结束,下载本文需要
想免费下载本文?
定制HR最喜欢的简历
下载文档到电脑,同时保存到云知识,更方便管理
加入VIP
还剩5页未读,
定制HR最喜欢的简历
你可能喜欢android,利用layoutParams代码动态布局空间位置
开发:LayoutParams的用法
LayoutParams继承于Android.View.ViewGroup.LayoutParams.
LayoutParams相当于一个Layout的信息包,它封装了Layout的位置、高、宽等信息。假设在屏幕上一块区域是由一个Layout占领的,如果将一个View添加到一个Layout中,最好告诉Layout用户期望的布局方式,也就是将一个认可的layoutParams传递进去。
可以这样去形容LayoutParams,在象棋的棋盘上,每个棋子都占据一个位置,也就是每个棋子都有一个位置的信息,如这个棋子在4行4列,这里的&4行4列&就是棋子的LayoutParams。
但LayoutParams类也只是简单的描述了宽高,宽和高都可以设置成三种值:
1,一个确定的值;
2,FILL_PARENT,即填满(和父容器一样大小);
3,WRAP_CONTENT,即包裹住就好。
在JAVA中动态构建的布局,常常这样写:
setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
上面这一句话其实是子对父的,也就是说,父布局下的子控件要设置这句话。
因为布局很多,虽然都继承至ViewGroup但是各个布局还是有很大的不同。
很显然上面这句应该这样写才算准确:
setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT,TableRow.LayoutParams.FILL_PARENT));
这表示这个子控件的父布局是一个TableRow , 这样的LayoutParams 太多,所以应明确指明。
下面分别说下两个常用到布局:
1. FrameLayout下动态设置子控件居中,动态用JAVA代码要这样实现:这表示这个子控件的父布局是一个TableRow , 这样的LayoutParams 太多,所以应明确指明。
下面分别说下两个常用到布局:
1. FrameLayout下动态设置子控件居中,动态用JAVA代码要这样实现:
FrameLayout.LayoutParams lytp = new FrameLayout.LayoutParams(80,LayoutParams.WRAP_CONTENT);
lytp .gravity = Gravity.CENTER;
btn.setLayoutParams(lytp);
2. RelativeLayout下动态设置子控件居中:
RelativeLayout.LayoutParams lp=new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
lp.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
btn1.setLayoutParams(lp);
从网页响应获取Json 对象,并解析
@SuppressWarnings(unchecked)
Map markJsonMap = (Map) mapJson.get(adlogo);
if(markJsonMap != null){
String position = (String) markJsonMap.get(position);
String markTumbString = (String) markJsonMap.get(thumb);
String smlscreen = (String) markJsonMap.get(smlscreen);
String bigscreen = (String) markJsonMap.get(bigscreen);
HomeActivity.mCornerMark.setPosition(position);
HomeActivity.mCornerMark.setThumb(markTumbString);
HomeActivity.mCornerMark.setSmlscreen(smlscreen);
HomeActivity.mCornerMark.setBigscreen(bigscreen);
setCornerMark();
解析后代码设置角标图片的大小,位置,异步下载图片
* 动态设置角标位置
private void setCornerMark(){
if(!HomeActivity.mCornerMark.getThumb().equals() && HomeActivity.mCornerMark.getThumb().length() != 0)
WindowManager wm = (WindowManager) mContex
.getSystemService(Context.WINDOW_SERVICE);
int width = wm.getDefaultDisplay().getWidth();
int height = wm.getDefaultDisplay().getHeight();
FrameLayout.LayoutParams reParams = (android.widget.FrameLayout.LayoutParams) HomeActivity.home_surface_viewLyout.getLayoutParams();
int width = reParams.
int height = reParams.
RelativeLayout.LayoutP
//width, height * 48 / 128
//获取控件布局参数
Configuration config = mContex.getResources().getConfiguration();
if (config.orientation == Configuration.ORIENTATION_LANDSCAPE)
String[] paramString = HomeActivity.mCornerMark.getBigscreen().split(,);
int whidthString = Integer.parseInt(paramString[0]);
int heightString = Integer.parseInt(paramString[1]);
whidthString = DensityUtil.px2dip(mContex,whidthString);
heightString = DensityUtil.px2dip(mContex,heightString);
params = new LayoutParams(whidthString,heightString);
String[] paramString = HomeActivity.mCornerMark.getSmlscreen().split(,);
int whidthString = Integer.parseInt(paramString[0]);
int heightString = Integer.parseInt(paramString[1]);
whidthString = (int) (width*0.005*whidthString);
heightString = (int) (height*0.005*heightString);
whidthString = DensityUtil.px2dip(mContex,whidthString);
heightString = DensityUtil.px2dip(mContex,heightString);
params = new RelativeLayout.LayoutParams(whidthString,heightString);
//动态指定控件大小,位置
Log.v(Position, HomeActivity.mCornerMark.getPosition());
if(HomeActivity.mCornerMark.getPosition().equals(1)){
params.leftMargin=20;
params.topMargin=20;
params.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
params.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
else if(HomeActivity.mCornerMark.getPosition().equals(2)){
params.rightMargin=20;
params.topMargin=20;
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
params.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
}else if (HomeActivity.mCornerMark.getPosition().equals(3)) {
params.leftMargin=20;
params.bottomMargin=20;
params.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
}else if(HomeActivity.mCornerMark.getPosition().equals(4)){
params.rightMargin=20;
params.bottomMargin=20;
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
HomeActivity.img_cornermark.setLayoutParams(params);
DownLoadTask downLoadTask = new DownLoadTask(HomeActivity.img_cornermark);
downLoadTask.execute(HomeActivity.mCornerMark.getThumb());
遇到的问题:
1. 在RelativeLayout里的布局,图片不显示?
RelativeLayout 层次布局是通过xml 文件 Relativelayout 由底层到外层进行布局的 ,应该在底层布局之上
2.在RelativeLayout里,代码实现位置是用
params.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
params.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
3.不同手机分辨率等比列显示:
String[] paramString = HomeActivity.mCornerMark.getSmlscreen().split(,);
int whidthString = Integer.parseInt(paramString[0]);
int heightString = Integer.parseInt(paramString[1]);
whidthString = (int) (width*0.005*whidthString);
heightString = (int) (height*0.005*heightString);
whidthString = DensityUtil.px2dip(mContex,whidthString);
heightString = DensityUtil.px2dip(mContex,heightString);
params = new RelativeLayout.LayoutParams(whidthString,heightString);静心格物致知
Android开发_精准排布控件位置
在Android系统上开发程序,很多时候需要精准的排布控件的位置和大小.并且适合各种比例的屏幕(4:3,16:9…),下面分别介绍在高版本和低版本的Android中的实现方法.
Android Studio/高版本Android实现
使用高版本android内置的android-support-percent-lib库,通过设置百分比的方法,实现了该功能, Demo一般都是android studio,Eclipse下需要下载支持库:
在Layout中设置百分比:PercentRelativeLayout/PercentFrameLayout/PercentLinearLayout
Layout文件
&?xml version="1.0"encoding="utf-8"?&
&android.support.percent.PercentFrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"&
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#44ff0000"
android:text="width:30%,height:20%"
app:layout_heightPercent="20%"
app:layout_marginLeftPercent="10%"
app:layout_marginTopPercent="40%"
app:layout_widthPercent="30%"/&
&/android.support.percent.PercentFrameLayout&3)
相关属性:
layout_widthPercent
layout_heightPercent
layout_marginPercent
layout_marginLeftPercent
layout_marginTopPercent
layout_marginRightPercent
layout_marginBottomPercent
layout_marginStartPercent
layout_marginEndPercent
修改build.gradle
在dependencies{}加
compile 'com.android.support:percent:22.2.0'
使用Eclipse/低版本Android实现
推荐用此方法,它的通用性更强,适合各个Android版本,无需外加扩展库,对于layout按一定比例或规则排列的界面更方便使用。
Layout文件
&?xml version="1.0" encoding="utf-8"?&
&RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"&
android:id="@+id/txt"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_gravity="left|top"
android:background="#44ff0000"
android:text="testme"/&
&/RelativeLayout&
package com.test.
import android.app.A
import android.os.B
import android.widget.TextV
import android.widget.RelativeL
public class testme extends Activity {
public void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView txtView = (TextView) findViewById(R.id.txt);
RelativeLayout.LayoutParams params =(RelativeLayout.LayoutParams)txtView.getLayoutParams();
params.width = 100;
params.height = 100;
params.setMargins(100,200,0,0);
txtView.setLayoutParams(params);
没有更多推荐了,}

我要回帖

更多关于 andriod studio安装 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信