導航:首頁 > 編程語言 > 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

友情鏈接