【问题标题】:Height half fill_parent xml半高 fill_parent xml
【发布时间】:2018-03-28 15:35:44
【问题描述】:

如何在 xml 中处理 LinearLayout 半高 fill_parent

<LinearLayout android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:weightSum="1">
      <ImageView android:layout_height="fill_parent"
                 android:layout_width="0dp"
                 android:layout_weight="0.5"/>
</LinearLayout>

我想对身高做类似的事情。

【问题讨论】:

  • 而不是 fill_parent 在 dp 中指定所需的值。像 100dp 或任何你想要的。
  • 你想让你的linearLayout是平方的吗?
  • 我只想有一半的屏幕和 1 个线性布局和另一半的屏幕

标签: android xml height android-linearlayout


【解决方案1】:

I just want have a half of screen with 1 linearLayout and half screen with other one

试试这个

<?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="match_parent"
    android:weightSum="2"
    android:orientation="vertical" >

    <LinearLayout android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="#192832"></LinearLayout>

    <LinearLayout android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="#193222"></LinearLayout>


</LinearLayout>

两个线性布局,每个占据屏幕的一半。

【讨论】:

  • 固定高度也可以使用 layout_height="0dp"
  • 请注意,fill_parent 已被弃用。对于 API 8 或更高版本,请使用 match_parent。 (docs)
  • 谢谢基思。编辑为 fill_parent
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-07-31
  • 1970-01-01
  • 1970-01-01
  • 2013-10-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多