如何填充10%的Android屏幕?

时间:2010-07-08 15:58:27

标签: android

如何在屏幕上填充2种水平颜色,这样下来的颜色会占到屏幕的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 个答案:

答案 0 :(得分:1)

你会想要使用fill_parent而不是包裹内容,如果上半部分的权重为9而下部的权重为1,那么应该起作用。权重应该占总权重的百分比,所以9 + 1 = 10和1/10是10%。