android - layout_weight=1.0 没有效果

标签 android android-layout

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

    <TextView
        android:id="@+id/tv_label_client_host"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:text="@string/label_host" />
    <EditText
        android:id="@+id/et_client_host"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:ems="10" 
        android:inputType="text"
        android:layout_weight="1.0"
        android:lines="1" />
</LinearLayout>

我希望 EditText 填充水平剩余的整个空间,但 TextViewEditText 获得可用空间的 1/2。此 LinearLayout 放置在另一个垂直 LinearLayout 内。

最佳答案

删除

   android:ems="10"

对于所有元素,我在这里进行了测试并且它有效。

关于android - layout_weight=1.0 没有效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12727033/

相关文章:

java - 从 android 中的 R 类获取名称

android - 从设备 : EOF Android Studio 3. 2.1 获取屏幕截图时出现意外错误

android - 在 RelativeLayout 中居中

android - 有什么办法可以改变单选按钮的颜色?

java - Robotium断言失败

Android - 为什么我不能覆盖 SeekBar 的 onProgressRefresh 方法?

Android ADT 在 Eclipse Neon.2 中无法识别

Android从不同的资源文件夹中挑选图像和样式

android - LayoutInflater 和 onFinishInflate()

android - AppCompatTextView 重心在 android 20 (KitKat) 中不起作用