我正在尝试了解相对布局是如何工作的。我知道如果我使用LinearLayout,我会有两个编辑文本字段,并排,水平。使用'weight‘将使edittext字段仅根据屏幕大小调整大小。(它可能看起来很奇怪,但它会做到的)。
我知道线性布局不是最有效的。我可以使用相对布局并具有相同的效果吗?我不想指定大小,我只想扩展edittext。
使用这样的线性布局,xml看起来会是什么样子?
谢谢你,迈克
发布于 2012-11-20 07:43:06
我能看到的一件事是大多数android开发人员都在布局上花费了毕生精力。
看起来你可以用RelativeLayouts做我想做的事情,但只能用2..at的倍数,至少到目前为止我发现的是这样。在按钮中心,两个按钮放在同一行上,每个按钮占据大约半个屏幕。如果没有按钮中心,它们会相互重叠。不知道这是否值得。
希望这能对大家有所帮助,谢谢大家!
<View android:id="@+id/button_center" android:layout_width="0dp"
android:layout_height="0dp" android:layout_centerHorizontal="true" />
<Button android:id="@+id/btnButton1" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="Button 1"
android:layout_toLeftOf="@+id/button_center"/>
<Button android:id="@+id/btnButton2" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="Button 2"
android:layout_toRightOf="@+id/button_center" />
发布于 2012-11-19 23:01:37
我认为这可以使用alignLeft/alignRight来完成,但不幸的是,似乎需要嵌套的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" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true" >
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="Left" >
<requestFocus />
</EditText>
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="Right" />
</LinearLayout>
</RelativeLayout>发布于 2012-11-19 23:04:56
如果您只是在EditText字段中使用width="fill_parent“和height="fill_parent”(可能还会使用一些填充或边距)呢?
https://stackoverflow.com/questions/13456350
复制相似问题