代码之家  ›  专栏  ›  技术社区  ›  Student

如何填充10%的Android屏幕?

  •  1
  • Student  · 技术社区  · 16 年前

    我怎样才能用两种水平颜色来填充屏幕,这样向下的一种会得到屏幕的10%?(像工具栏)?

    我正在尝试修改 Linear Layout example 到:

    <?xml version="1.0" encoding="utf-8"?>
    
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
    
      <LinearLayout
          android:orientation="horizontal"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:layout_weight="1">
          <TextView
              android:text="green"
              android:gravity="center_horizontal"
              android:background="#00aa00"
              android:layout_width="wrap_content"
              android:layout_height="fill_parent"
              android:layout_weight="1"/>
          <TextView
              android:text="blue"
              android:gravity="center_horizontal"
              android:background="#0000aa"
              android:layout_width="wrap_content"
              android:layout_height="fill_parent"
              android:layout_weight="1"/>
      </LinearLayout>
    
      <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1">
        <TextView
            android:text="single row"
            android:textSize="15pt"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"/>
      </LinearLayout>
    
    </LinearLayout>
    

    但是如果改变

    android:layout_height="fill_parent"
    

    对于

    android:layout_height="wrap_content"
    

    在下面的“面板”(它是面板吗?)文本显示不完整。

    1 回复  |  直到 16 年前
        1
  •  1
  •   Maximus    16 年前

    您将希望使用填充父级而不是包装内容,并且如果上半部分的权重为9,下半部分的权重为1,则应该工作。重量应占总重量的百分比,因此9+1=10和1/10为10%。