0

私はLinearLayout別の中にありLinearLayoutます。私が抱えている問題はToggleButton、2番目に表示されないことLinearLayoutです。これが私の完全なUIです。また、このレイアウト設計が効率的かどうかも知りたいです。使用できることはわかっていますTableLayoutが、3つのコンポーネントを1行に収めるのに問題があります

<?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

AutoCompleteTextView に layout_weight を割り当ててみてください。

    <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 に答える
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 に答える
0

これは、AutoCompleteTextView が幅全体を使用したためです。次のように変更します。

android:layout_width="wrap_content"

または、固定サイズ (60 dp など) を使用します。

于 2012-08-28T08:27:31.780 に答える