我正试图平衡我的EditText
的意见。 但我似乎无法让他们排队正确,我不能增加EditText
的大小。起初,我用RelativeLayout
试了一下,这让我能够准确地定位事物,但尺寸依然不足。我想如果我切换到水平LinearLayout
那么我可以用layout_weight
调整这两个字段,而EditText
会自动填满这个空间,但似乎并非如此。有什么建议吗? 在屏幕上显示时,此自定义视图被添加到垂直LinearLayout
。如何正确对齐水平LinearLayout中的TextView和EditText?
我的布局文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="1dp"
android:weightSum="1"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.6"
android:gravity="center_vertical"
android:textColor="@color/ws_blue"
android:background="#00ffff"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Settings Item: "
android:id="@+id/itemLabel" />
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.4"
android:textColor="@color/ws_blue"
android:textColorHint="@color/ws_hint"
android:background="#ffff00"
android:id="@+id/et_item_value" />
</LinearLayout>
Android Studio中预览:
从我的手机实际截图:
设置宽度0dp为textview和edittext当你把重量和余量留下来也编辑文本 –
@SathishKumarJ谢谢,我会检查出'TableLayout' –
@ Er.Arjunsaini这看起来正确的Android预览屏幕,但当我运行它时,它仍然与我上面的屏幕截图一样。 –