安卓布局方式的问题

zhang422173651 2012-08-13 12:37:16
如何在xml文件中布局,比如第一行前面是按钮后面跟文本框,第二行也是这样,第三行也是,忘了说了我用的是线性布局方式,我直接拖的控件,但是总有个问题,就是文本框不会和按钮同行,是错位的,这时我就只有调整layout_marginLeft
android:layout_marginTop来不断试,好费时间和经历,本人小白,求教你们怎么布局的,能否给个例子,谢谢了
...全文
207 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
ysxfight 2012-08-14
  • 打赏
  • 举报
回复
2楼做的正是楼主所需要的,好好参考下吧。
ysxfight 2012-08-14
  • 打赏
  • 举报
回复
2楼做的正是楼主所需要的,好好参考下吧。
Roly 2012-08-14
  • 打赏
  • 举报
回复
如果行数就多用1楼的方法好,如果行数比较少,就像你所说的只有三行,就用2楼的也不错。
另外如果你的多行数据之间是同一规律的,用tablelayout布局也可以。
leehao_vip 2012-08-14
  • 打赏
  • 举报
回复
tablelayout
占占 2012-08-14
  • 打赏
  • 举报
回复
或许可以用html布局,黎活明视频有详细讲述。
hvk687 2012-08-13
  • 打赏
  • 举报
回复
用listView吧,定义一个单行的item然后,用adepter去搞,简单明了
franzhong 2012-08-13
  • 打赏
  • 举报
回复
每两个卡在一个LinearLayout里
把宽设为fill_parent
wintergoes 2012-08-13
  • 打赏
  • 举报
回复
根据你所说的,你的按钮和文本框这样组合的行数应该是固定的
不是一个动态的列表
建议你使用tableLayout
TableLayout还可以自动对齐列,不用自己再去设置margin等来对齐
nuistchn 2012-08-13
  • 打赏
  • 举报
回复
同意1楼的建议,楼主可以去看一下listview的用法,很适合你的需求。
liangzuoting 2012-08-13
  • 打赏
  • 举报
回复
如果行数确定且少,如2L所述,如果不是如1L所说。
再有你用的Linear是不是有问题啊,用水平的,拖的话的确不容易拖对地方,你可以直接打开xml剪切复制一下嘛!
csdn_2013 2012-08-13
  • 打赏
  • 举报
回复
1、2L 正解~
wyx100 2012-08-13
  • 打赏
  • 举报
回复
listView 定义一个单行的item然后,用adepter
Cafe_ING 2012-08-13
  • 打赏
  • 举报
回复
用TableLayout可以使每行的控件在相应的列对齐啦,不然还可以设置下它们的layout_width或者设置它们的weight=1
AMinfo 2012-08-13
  • 打赏
  • 举报
回复

<?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="fill_parent"
android:orientation="vertical"
android:id="@+id/mainLayout">


<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<Button android:id="@+id/Button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="第1个按扭"/>

<EditText android:id="@+id/EditText01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="第1个文本编辑" />

</LinearLayout>

<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<Button android:id="@+id/Button02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="第2个按扭" />

<EditText android:id="@+id/EditText02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="第2个文本编辑" />


</LinearLayout>


<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<Button android:id="@+id/Button03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="第3个按扭"/>

<EditText android:id="@+id/EditText03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="第3个文本编辑" />

</LinearLayout>

</LinearLayout>

80,354

社区成员

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

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