0

我有一个LinearLayout里面另一个LinearLayout。我遇到的问题是ToggleButton在第二个中不可见LinearLayout..这是我的完整 UI。我也想知道这种布局设计是否有效。我知道我可以使用TableLayout,但是我在一条线上安装 3 个组件时遇到问题

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dip" >

<TextView
    android:id="@+id/supplierNameTV"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/supplierNameTV"
    android:textColor="#FFFFFF" 
    android:layout_gravity="right"/>

<LinearLayout android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 

    <AutoCompleteTextView
        android:id="@+id/supplierName_CB"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

    <ToggleButton
        android:id="@+id/toggleButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:checked="false"
        android:text="ToggleButton" />

</LinearLayout>
<TextView
    android:id="@+id/prodNameTV"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/prodNameTV"
    android:textColor="#FFFFFF" 
    android:layout_gravity="right"
    android:layout_marginBottom="5dip"
    android:layout_marginTop="5dip"/>

<AutoCompleteTextView
    android:id="@+id/prodName_CB"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"/>

<Button
    android:id="@+id/add_button"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/addproduct_button"
    android:textColor="#372c24" />


<ListView
    android:id="@+id/listview"
    android:layout_height="wrap_content"
    android:layout_width="match_parent">
</ListView>


</LinearLayout>
4

3 回答 3

1

使用 LinearLayout,您可以轻松分配布局权重。根布局将具有 100 的权重和,然后布局的其余部分将具有它们的权重。虽然在这种情况下我建议使用相对布局。原因是性能以及对不同屏幕的易于支持,因为布局是相对的。

例如在我的情况下,

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="100" >

<ListView
    android:id="@+id/mst"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="98" >
</ListView>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="2" >

    <Button
        android:id="@+id/btnDelete"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="@string/btn_delete" />

    <Button
        android:id="@+id/btnExport"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:text="@string/btn_export" />

    <Button
        android:id="@+id/btnSelectAll"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:text="@string/btn_select_all" />

</RelativeLayout>

于 2012-08-28T08:29:33.243 回答
1

尝试将 layout_weight 分配给您的 AutoCompleteTextView:

    <AutoCompleteTextView
    android:id="@+id/supplierName_CB"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    />
于 2012-08-28T08:30:52.543 回答
0

这是因为 AutoCompleteTextView 占据了整个宽度。将其更改为:

android:layout_width="wrap_content"

或使用固定尺寸(如 60dp)。

于 2012-08-28T08:27:31.780 回答