Android布局:结合LinearLayout和TableLaout

发布于 2024-11-28 14:42:10 字数 2127 浏览 4 评论 0原文

我想要一个看起来像这样的布局(在横向模式下): - 顶部 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我们只是彼此的过ke 2024-12-05 14:42:10

添加到

android:orientation="vertical" 

父 LinearLayout 中。

Add

android:orientation="vertical" 

in parent LinearLayout.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文