关于布局重量和边距

时间:2014-11-19 13:18:15

标签: android android-layout-weight

为什么当我设置layout_marginStart="130dp" button的属性EditText时,相应的整个weight = 9移位?

2-我计划将屏幕划分为4个部分,总<LinearLayout 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:orientation="vertical" android:weightSum="9" tools:context="${relativePackage}.${activityClass}" > <TableLayout android:id="@+id/table_0" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="4"> <TableRow android:id="@+id/row0" android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:id="@+id/tv_ip" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginStart="5dp" android:paddingTop="15dp" android:text="IP: "/> <EditText android:id="@+id/et_ip" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="12"/> </TableRow> <TableRow android:id="@+id/row1" android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:id="@+id/tv_port" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginStart="5dp" android:paddingTop="15dp" android:text="Port: "/> <EditText android:id="@+id/et_port" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="12"/> </TableRow> <TableRow android:id="@+id/row2" android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:id="@+id/tv_clientid" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginStart="5dp" android:paddingTop="15dp" android:text="Client_ID"/> <EditText android:id="@+id/et_clientid" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="12"/> </TableRow> <TableRow android:id="@+id/row3" android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:id="@+id/tv_cleansession" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginStart="5dp" android:paddingTop="15dp" android:text="Clean Session"/> <CheckBox android:id="@+id/cbx_cleansession" android:layout_width="match_parent" android:layout_height="wrap_content"/> </TableRow> <TableRow android:id="@+id/row4" android:layout_width="match_parent" android:layout_height="wrap_content"> <Button android:id="@+id/btn_conn" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginStart="130dp" android:gravity="center_vertical|center_horizontal" android:text="Connect"/> </TableRow> </TableLayout> 和1,2,3,4部分应为2 / 9,2 / 9,4 / 9,相应的1/9。如果我需要修改某些内容,请告诉我。

XML

{{1}}

1 个答案:

答案 0 :(得分:1)

1。从底部结束您的布局

</LenearLayout>
  1. 你最大限度地使用android:layout_marginStart="5dp"。如果您不想更改您的api virsion,请使用此android:layout_marginLeft=5dp

  2. 不要使用textview显示清洁会话。用这个。

    `

        <CheckBox
            android:id="@+id/cbx_cleansession"
            android:layout_width="match_parent"
            android:text="Clean Session"
            android:layout_height="wrap_content"/>
    </TableRow>`
    
  3. 最后一件事我只能使用EditText并给它提示。如果你想让它变得更好,那么你可以使用背景模板。
  4. 那就是它。我希望你喜欢它