Android TableRow中的固定宽度EditText
我完全无法在TableRow中获取固定宽度的EditText小部件。 我试图以相等的宽度并排放置两个EditText(大约20dip),但无论我尝试设置哪个属性,第一个EditText都是很长的,显然无法调整大小 非常感谢:Android TableRow中的固定宽度EditText,android,android-edittext,Android,Android Edittext,我完全无法在TableRow中获取固定宽度的EditText小部件。 我试图以相等的宽度并排放置两个EditText(大约20dip),但无论我尝试设置哪个属性,第一个EditText都是很长的,显然无法调整大小 非常感谢: <TableRow android:layout_height="wrap_content" android:baselineAligned="false" android:id="@+id/tableRow3" android:gravity=
<TableRow
android:layout_height="wrap_content"
android:baselineAligned="false"
android:id="@+id/tableRow3"
android:gravity="center"
android:stretchColumns="1"
android:layout_width="match_parent">
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
android:paddingLeft="36dip">
</TextView>
<EditText
android:layout_height="wrap_content"
android:id="@+id/editText2"
android:inputType="number"
android:layout_width="20dip">
</EditText>
<EditText
android:layout_height="wrap_content"
android:id="@+id/editText1"
android:inputType="number"
android:layout_width="wrap_content">
<requestFocus></requestFocus>
</EditText>
</TableRow>
我不知道TableLayout是实现这一点的最佳方式,它可能会很麻烦,除非您正在显示大量数据并需要使用它 我发现的确保表单对象按我希望的方式分布长度的最佳方法之一是使用权重,而不是显式声明宽度 请尝试以下操作:
<LinearLayout ... android:orientation="horizontal" ...
android:layout_width="match_parent" android:layout_height="wrap_content"
<TextView ... android:layout_width="0dp" ... android:layout_weight="50" />
<TextView ... android:layout_width="0dp" ... android:layout_weight="50" />
</LinearLayout>
将此属性添加到您的EditText
:
android:layout_weight="1"
适合我。非常感谢您的回复,我尝试了EditText,这是我尝试放置的组件,但它不起作用。老实说,我想我可能错过了一些基本的东西。我将回到教程并浏览它们。感谢您的回复:)我不知道为什么Pheonixblade会将权重设置为50,但是如果您声明宽度为0,并按照您通常应该的方式使用权重(使用1或2等),那么它将显示相等的列宽。如果将宽度设置为fill\u parent,则TextView中的内容将确定列宽。我只使用100作为权重和作为标准,以确保我知道发生了什么,您可以使用任何想要的权重。:)>Phoneixblade9-对我有用。我如你所述更改了我的应用程序布局设置。对我有用。谢谢。很高兴我能提供帮助,@SIVAKUMAR.J:)菲尔,如果回答了你的问题,请将答案标记为正确:)谢谢!