添加到线性布局时按钮不可见

时间:2012-10-06 11:25:25

标签: android android-layout

我想要显示表格和表格下方我希望在表格布局的中心显示按钮,所以我将两者都包裹在线性布局中,但现在它不显示。请帮我解决问题。 这是我的xml布局文件= -

<LinearLayout 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
        android:layout_marginLeft="40dp"
        android:layout_marginRight="40dip"
        android:layout_marginTop="30dp"
        android:layout_toRightOf="@id/item">
    <TableLayout
        android:id="@+id/itemTable"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/border"
        android:orientation="horizontal"
        android:padding="3dip" >
    </TableLayout>

    <Button
        android:id="@+id/btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:background="@drawable/list_selector"
        android:padding="10dp" 
        android:layout_gravity="center_horizontal"
        android:text=" Order " />
</LinearLayout>

4 个答案:

答案 0 :(得分:3)

android:orientation="vertical"添加到您的LinearLayout

答案 1 :(得分:2)

你有没有理由不使用RelativeLayout?

<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
    android:layout_marginLeft="40dp"
    android:layout_marginRight="40dip"
    android:layout_marginTop="30dp"
    android:layout_toRightOf="@id/item">
<TableLayout
    android:id="@+id/itemTable"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:background="@drawable/border"
    android:orientation="horizontal"
    android:padding="3dip" >
</TableLayout>

<Button
    android:id="@+id/btn"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:background="@drawable/list_selector"
    android:padding="10dp" 
    android:layout_below="@+id/itemTable"
    android:layout_gravity="center_horizontal"
    android:text=" Order " />
 </RelativeLayout>

这样它应该在布局中很好地适应。

如果您的问题是您没有看到按钮,也许您的桌子太大了?您应该将它缩小,或者将所有内容放在一个漂亮的ScrollView中

答案 2 :(得分:0)

将scrollView添加为父级:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scroll_view"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

<LinearLayout 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
        android:layout_marginLeft="40dp"
        android:layout_marginRight="40dip"
        android:layout_marginTop="30dp"
        android:layout_toRightOf="@id/item">
    <TableLayout
        android:id="@+id/itemTable"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/border"
        android:orientation="horizontal"
        android:padding="3dip" >
    </TableLayout>

    <Button
        android:id="@+id/btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:background="@drawable/list_selector"
        android:padding="10dp" 
        android:layout_gravity="center_horizontal"
        android:text=" Order " />
</LinearLayout>

</Scrollview>

答案 3 :(得分:0)

将android:gravity =“center_horizo​​ntal”添加到线性布局,并将LinearLayout的方向设置为Vertical。

相关问题