请教一个布局问题

lvlianghui 2012-02-26 01:09:53
我想我的应用上下布局,下面是一排按钮,上面是文本。用LinearLayout,怎样能使下面的按钮wrap_content,然后上面的内容填充剩下的空间呢?我上面用fill_parent,则下面的按钮就看不到了。
...全文
87 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
tony-杨 2012-03-04
  • 打赏
  • 举报
回复
这个一般都是用RelativeLayout布局、注意几个属性值:layout_alignParentBottom、layout_marginBottom
下面是我一个Demo中的布局你可以参考下


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#CCC"
>

<LinearLayout
style="@style/Common_Top_Box"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<EditText
android:id="@+id/http_down_url"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:textSize="18dip"
android:hint="输入待下载地址"
></EditText>
<EditText
android:id="@+id/http_down_local_filename"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:textSize="18dip"
android:hint="输入本地待保存文件名"
></EditText>
<EditText
android:id="@+id/http_down_thread_num"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:textSize="18dip"
android:hint="下载线程数"
android:text="8"
></EditText>
<ProgressBar
android:id="@+id/http_down_progress"
android:layout_width="fill_parent"
android:layout_height="20dip"
android:layout_marginTop="10dip"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
style="?android:attr/progressBarStyleHorizontal"
></ProgressBar>
<TextView
android:id="@+id/http_down_filesize"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_marginTop="5dip"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:textColor="#FF000000"
android:text="文件大小:/下载进度:"
></TextView>
</LinearLayout>


<LinearLayout
style="@style/Common_Bottom_Button_Group"
android:layout_width="fill_parent"
>
<Button
android:id="@+id/http_down_btn_img"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:layout_weight="1"
android:text="看图片"
></Button>
<Button
android:id="@+id/http_down_btn_file"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:layout_weight="1"
android:text="下文件"
></Button>
</LinearLayout>

</RelativeLayout>



<style name="Common_Top_Box">
<item name="android:layout_marginBottom">60dip</item>
<item name="android:orientation">vertical</item>
<item name="android:layout_alignParentLeft">true</item>
</style>
<style name="Common_Bottom_Button_Group">
<item name="android:background">@android:color/darker_gray</item>
<item name="android:gravity">center_horizontal</item>
<item name="android:paddingTop">5dip</item>
<item name="android:layout_height">60dip</item>
<item name="android:layout_alignParentBottom">true</item>
</style>
j_f0001 2012-02-27
  • 打赏
  • 举报
回复
用相对布局,把上面的布局设置 layout_above="下面布局的id就可以了,
2在路上 2012-02-27
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 a328240784 的回复:]

weigth属性
[/Quote]
+1
zw19880717 2012-02-27
  • 打赏
  • 举报
回复
试试把下面的按钮设置成fill_parent,然后layout设成fill_parent,然后设置下button的高度
Rain麦子 2012-02-27
  • 打赏
  • 举报
回复
上面的控件 weigth 属性 为1
下面的控件 android:layout_height="wrap_content"
追风筝的孩子 2012-02-26
  • 打赏
  • 举报
回复
weigth属性

80,337

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧