溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

android 相對布局 水平平分父控件容器

發(fā)布時間:2020-07-05 13:32:05 來源:網(wǎng)絡(luò) 閱讀:4430 作者:x1230x 欄目:移動開發(fā)

剛才用相對布局的時候,需要用到子控件水平平分父控件的容器。可是在百度上找了半天沒有什么可行的辦法,所以就自己研究了下。現(xiàn)在我發(fā)現(xiàn)了一種比較麻煩的方法,不過能解決問題也算可以了,如果有朋友有更好的方法,希望不吝告訴下。好了,我所說的方法就是,在兩個 button 中間 再放一個textview 或者其他什么的,只是用來作為一個中間位置參考的,將textView 設(shè)置水平居中(android:layout_centerHorizontal="true"),然后 分別將需要水平平分父容器的兩個button 設(shè)置 android:layout_toLeftOf="@+id/textview "   android:layout_toRightOf="@+id/textview " 屬性,最后將兩個button的寬度設(shè)置fill_parent 就行了。

下面是測試的布局代碼:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.first_summary.MainActivity$PlaceholderFragment" >

    <ImageButton
        android:id="@+id/ImageButton"
        android:contentDescription="@+id/ImageButton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />
    
    <Button 
        android:id="@+id/up"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/ImageButton"
        android:layout_toLeftOf="@+id/cencer"
        android:textSize="12sp"
        android:text="上傳數(shù)據(jù)"
        />
    <TextView
        android:id="@+id/cencer"
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_below="@+id/ImageButton"
        android:layout_centerHorizontal="true"
        />
     <Button 
        android:id="@+id/add"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/ImageButton"
        android:layout_toRightOf="@+id/cencer"
        android:textSize="12sp"
        android:text="添加數(shù)據(jù)"
        />
  </RelativeLayout>


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI