请教大侠,linearLayout自适应布局的问题。请进。

xjj2000 2011-12-13 10:48:23
如题,我想在一行里,先放个文本框,再放个固定宽度的按钮。文本框宽度填满剩余的空间,能实现吗?
...全文
352 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
android_baiyuchuan 2011-12-14
  • 打赏
  • 举报
回复
<LinearLayout android:weightSum="5">

<EditText layout_weight="1"/>
设为1就代表占父的1/5 设为5就全占 ;但是若还有其他的子和他并列,就会占父的全部 ,但是会给另外的子留下一部分空间来显示。

Byron_ 2011-12-14
  • 打赏
  • 举报
回复

<EditText
android:id="@+id/editText1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_toLeftOf="@+id/button1" >
</EditText>


注意layout_weight="1"就是布局比重的重点。
安卓机器人 2011-12-14
  • 打赏
  • 举报
回复


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>

<EditText
android:id="@+id/editText1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_toLeftOf="@+id/button1" >
</EditText>

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>




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

<EditText
android:id="@+id/editText1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@+id/button1" >
</EditText>

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="Button" />
</RelativeLayout>
Android_Robot 2011-12-14
  • 打赏
  • 举报
回复
其实最方便的就是在ADT里面xxx.xml预览页面拖控件就OK了,就和.net一样,最新的ADT很强大的
xjj2000 2011-12-14
  • 打赏
  • 举报
回复
我试过了,按钮在文本框后面的话,fill_parent的文本框会占据整个一行的宽度,把按钮挤到屏幕外面去了。
安卓android 2011-12-14
  • 打赏
  • 举报
回复
木有march_parent属性,只有fill_parent和wrap_content属性
youhun_1 2011-12-14
  • 打赏
  • 举报
回复
同意楼上的 给文本框设置match_parent属性,给按钮设置个绝对值的属性就可以。
Birds2018 2011-12-14
  • 打赏
  • 举报
回复
fill_parent属性。 或者计算好屏幕宽度,因为按钮是固定宽度的,所以剩下的宽度全部给文本框,设置个dip绝对值
xjj2000 2011-12-14
  • 打赏
  • 举报
回复
谢谢各位,解决了,谢谢!!!!!给分了哦

80,350

社区成员

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

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