Android布局:结合LinearLayout和TableLaout
我想要一个看起来像这样的布局(在横向模式下): - 顶部 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
I would like to have a layout that looks like this (in landscape mode):
- on top 4 equally spaced button
- in middle: an EditText block and next to it on its right an ImageButton
- at the bottom a textview.
Here is the xml file that I used to implement this layout:
<?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>
However, what I say is 4 buttons on top the way I want, and the rest (second row and third row) is not on the page (cannot be seen). I don't know where they have gone.
I appreciate any help for this.
Thanks,
TJ
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
添加到
父 LinearLayout 中。
Add
in parent LinearLayout.