【问题标题】:Android layout: combining LinearLayout and TableLaoutAndroid布局:结合LinearLayout和TableLaout
【发布时间】:2011-10-22 11:17:01
【问题描述】:

我想要一个看起来像这样的布局(在横向模式下): - 顶部 4 个等距按钮 - 中间:一个 EditText 块,右边是一个 ImageButton - 在底部一个文本视图。

这是我用来实现此布局的 xml 文件:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:padding="20dip"
>


<TableLayout 
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:stretchColumns="*">

<TableRow>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="@drawable/b1"
android:drawablePadding="5sp"
android:text="B1"></Button>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="@drawable/b2"
android:drawablePadding="5sp"
android:text="B2"></Button>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="@drawable/b3"
android:drawablePadding="7sp"
android:text="B3"></Button>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="@drawable/b4"
android:drawablePadding="7sp"
android:text="B4"></Button>

</TableRow>   
</TableLayout> 

<TableLayout 
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:stretchColumns="*">

<TableRow>

<EditText 
android:id="@+id/entry"
android:layout_width="200dp"
android:layout_height="50dp"
android:layout_below="@id/e1"
android:layout_marginLeft="20dp" 
android:layout_marginTop="10dp"  
/>
<ImageButton
android:id="@+id/search2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/i1" 
android:layout_marginTop="10dp" 
/>  

</TableRow>

<TextView
android:id="@+id/t2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="T2"/>

</TableLayout> 

</LinearLayout> 

但是,我说的是顶部的 4 个按钮按我想要的方式,其余的(第二行和第三行)不在页面上(看不到)。我不知道他们去了哪里。 我感谢任何帮助。 谢谢,

TJ

【问题讨论】:

    标签: android android-linearlayout tablelayout


    【解决方案1】:

    添加

    android:orientation="vertical" 
    

    在父线性布局中。

    【讨论】:

    • 谢谢,这就是问题所在,感谢您的帮助。
    • ...因为 LinearLayout 的默认方向是水平的。
    猜你喜欢
    • 2012-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-27
    相关资源
    最近更新 更多