android - 扩展 Android edittext 扩展到屏幕边缘

标签 android android-edittext

我有一个带有 textview 和 edittext 的相对布局。 edittext 在同一行与 textview 的左(或右)对齐。

如何让edittext延伸到屏幕的最边缘(使用xml)。 设置宽度不合适,因为我可能有不同的分辨率。

最佳答案

如果你想使用 TableLayout,你可以使用下面的代码。也可以使用 TableLayout。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    tools:context=".MainActivity" >

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:stretchColumns="*"
        android:shrinkColumns="*">

        <TableRow
            android:id="@+id/tableRow1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="5dp" >

            <TextView
                android:id="@+id/textView"
                android:layout_weight="3"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:text="Username"
                android:textAppearance="?android:attr/textAppearanceLarge" />

            <EditText
                android:id="@+id/editText"
                android:layout_weight="7"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:ems="5"
                android:hint="Password"
                android:textAppearance="?android:attr/textAppearanceLarge" />

        </TableRow>
        </TableLayout>
    </LinearLayout>

关于android - 扩展 Android edittext 扩展到屏幕边缘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47007119/

相关文章:

java - 在Android应用程序中将字符串转换为整数

android - 如何删除我的编辑文本上的 ` frequently used email ` toast?

android - 如何使 native 库可选

android - 在 Android 上定位 SQLite 数据库文件

java - edittext 中的值在获得焦点之前不会显示。安卓

android - Dialog 的 setSoftInputMode 在键入时不隐藏 EditText?

android - 是否可以使用android :inputType with a string resource

java - 通过单击按钮使用 BaseAdapter 将 EditText 值添加到 ListView 时出错

java - 在不获取 "Suspicious sign in prevented"的情况下发送电子邮件的替代方法

java - Volley Post 请求在 onResponse 内未返回任何响应