导航:首页 > 编程语言 > androidlayout代码

androidlayout代码

发布时间:2021-02-21 14:04:20

『壹』 android中如何用代码设置layout_centerInParent属性

这个属性好像没有对应的方法!

『贰』 android用代码怎么设置layout

代码中可以布局layout,有专门的layout类,你查下资料吧,
不过还是建议尽量在xml中布局layout,代码中会增加程序运行负担,请采纳谢谢

『叁』 android 用代码编写linearlayout布局

在xml里添加android:padding="";
""里加数字即可

『肆』 android:layout_span可以用代码实现吗

View tabChildView = new View(this); //比如这个view是你放在TableLayout中的
LayoutParams lp = tabChildView.getLayoutParams(); //先得到这个view原先的布局参数
//构造一个TableRow.LayoutParams,它是子类版,把lp传进去这样权之前的布局参数就在该子类中了
TableRow.LayoutParams tlp = new TableRow.LayoutParams(lp);
tlp.span = 3;//TableRow.LayoutParams可以设置这个属性
tabChildView.setLayoutParams(tlp); //别忘了把参数设置回去

『伍』 android怎么把用代码写layout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
</LinearLayout>
这个意思吗

『陆』 Android自定义layout怎么写

LinearLayout自定义方法有多种:
1、自定义xml布局,然后加载布局,自定义一个View继承LinearLayout
2、在自定义控件中声明它的所有子元素,然后在Layout文件中像使用LinearLayout一样去进行布局。

第二种比较烦 ,它需要在Layout文件中定义好子元素之后,要在代码 onFinishInflate() 进行匹配子元素。

我就说说加载布局文件的方法吧。
首先:定义好layout文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="

android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >

<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:paddingBottom="5dip"
android:paddingLeft="40dip"
android:paddingTop="5dip"
android:src="@drawable/right_icon" />

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="8dip"
android:text="主题"
android:textColor="#000000" />
<LinearLayout
android:layout_width="100dp"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:paddingBottom="5dip"
android:paddingLeft="12dip"
android:paddingTop="5dip"
android:src="@drawable/home_icon" />
<ImageView
android:id="@+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:paddingBottom="5dip"
android:paddingLeft="12dip"
android:paddingTop="5dip"
android:src="@drawable/add_icon" />
</LinearLayout>

</LinearLayout>
public class MyLinearLayout extends LinearLayout {

private ImageView imageView,iv_home,iv_add;
private TextView textView;

public MyLinearLayout (Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public MyLinearLayout (Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
LayoutInflater inflater=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.actionbar, this);
imageView=(ImageView) findViewById(R.id.imageView1);
iv_home=(ImageView) findViewById(R.id.imageView2);
iv_add=(ImageView) findViewById(R.id.imageView3);
textView=(TextView)findViewById(R.id.textView1);

}

/**
* 设置图片资源
*/
public void setImageResource(int resId) {
imageView.setImageResource(resId);
}

/**
* 设置显示的文字
*/
public void setTextViewText(String text) {
textView.setText(text);
}

}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="

android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >

<cn.com.demo.view.MyLinearLayout
android:id="@+id/ll_actionbar"
android:layout_height="fill_parent<span style="font-family: Tahoma, 'Microsoft Yahei', Simsun;">" </span>
android:layout_width="wrap_content"
android:background="@drawable/bg"
/>
</LinearLayout>
接下来自定义一个MyLinearLayout继承LinearLayout,并且加载刚刚写好的layout文件。(比如http://www.tiecou.com)
public class MyLinearLayout extends LinearLayout {
private ImageView imageView,iv_home,iv_add;
private TextView textView;
public MyLinearLayout (Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public MyLinearLayout (Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
LayoutInflater inflater=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.actionbar, this);
imageView=(ImageView) findViewById(R.id.imageView1);
iv_home=(ImageView) findViewById(R.id.imageView2);
iv_add=(ImageView) findViewById(R.id.imageView3);
textView=(TextView)findViewById(R.id.textView1);
}
/**
* 设置图片资源
*/
public void setImageResource(int resId) {
imageView.setImageResource(resId);
}

/**
* 设置显示的文字
*/
public void setTextViewText(String text) {
textView.setText(text);
}
}
最后,要的时候使用定义好的MyLinearLayout控件。

『柒』 在java中点击Button如何把 android:layout_alignParentBottom="True"改为false,代码中实现,谢谢

假设你要操作的控件内叫容v

RelativeLayout.LayoutParamsparams=
(RelativeLayout.LayoutParams)v.getLayoutParams();
params.removeRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
v.setLayoutParams(params);

『捌』 android absolutelayout的layout_x和layout_y在代码里的表示

这个布局我现在从见被使用过,要不要考虑换一个别的用用,比如constraintlayout

『玖』 android怎么用java代码动态给layout的textview设置text

1 <TextView android:id="@+id/Title" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:drawableRight="@drawable/check_down" android:gravity="center_vertical" android:textSize="24dip" android:maxLines="1" android:ellipsize="end"/> 我们写在xml的时候,都是这么写的。那代码呢?我们发现TextView他有一个方法 2 public void setCompoundDrawables (Drawable left, Drawable top, Drawable right, Drawable bottom); 这个方法呢,就是可以在Java代码动态的画 左上右下几个方向 类似于xml中的 android:drawableLeft="@drawable/icon" android:drawableTop="@drawable/icon" android:drawableRight="@drawable/icon" android:drawableButtom="@drawable/icon" 3 具体在代码中的用法是: Drawable drawable = getResources().getDrawable(R.drawable.spinner_checked); drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); //设置边界 titleTv.setCompoundDrawables(null, null, drawable, null);//画在右边 4 运行之后的效果 如何在代码中动态为TextView设置drawableRight 如何在代码中动态为TextView设置drawableRight 5 界面比较丑,勿喷,大家也还可以通过这个方法实现 public void (Drawable left, Drawable top, Drawable right, Drawable bottom)

『拾』 Android中view 怎样通过代码设置 layout

Android动态改变View控件大小layout的方法:
1、声明控件参数获取对象 LayoutParams lp;
2、获回取控件参数: lp = 控件id.getLayoutParams();
3、设置控件参数:如高度。 lp.height -= 10;
4:、使设置生效:控答件id.setLayoutParams(lp);
例如如要把Imageview下移200px: ImageView.setPadding( ImageView.getPaddingLeft(), ImageView.getPaddingTop()+200, ImageView.getPaddingRight(), ImageView.getPaddingBottom());

阅读全文

与androidlayout代码相关的资料

热点内容
网络中常用的传输介质 浏览:518
文件如何使用 浏览:322
同步推密码找回 浏览:865
乐高怎么才能用电脑编程序 浏览:65
本机qq文件为什么找不到 浏览:264
安卓qq空间免升级 浏览:490
linux如何删除模块驱动程序 浏览:193
at89c51c程序 浏览:329
怎么创建word大纲文件 浏览:622
袅袅朗诵文件生成器 浏览:626
1054件文件是多少gb 浏览:371
高州禁养区内能养猪多少头的文件 浏览:927
win8ico文件 浏览:949
仁和数控怎么编程 浏览:381
项目文件夹图片 浏览:87
怎么在东芝电视安装app 浏览:954
plc显示数字怎么编程 浏览:439
如何辨别假网站 浏览:711
宽带用别人的账号密码 浏览:556
新app如何占有市场 浏览:42

友情链接