0

我的 XML 如下:

<LinearLayout
    android:orientation="vertical"
    android:id="@+id/llBottom"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:weightSum="2" >
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:id="@+id/llPhone"
        android:layout_weight=".9"
        android:gravity="center" >
        <ImageView
            android:id="@+id/ivMyPhone"
            android:layout_width="@dimen/about_logo_size"
            android:layout_height="@dimen/about_logo_size"
            android:src="@drawable/andicon" />
    </LinearLayout>
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:id="@+id/llPhoneInfo"
        android:layout_weight="1.1"
        android:weightSum="6"
        android:gravity="center" >
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:id="@+id/llBrand"
        android:layout_below="@+id/llPhone"
        android:weightSum="2"
        android:layout_weight="1"
        android:gravity="center" >
        <TextView
            android:id="@+id/tvBrand"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="Phone Brand: "
            android:layout_weight="1" />

        <TextView
            android:id="@+id/tvBrandName"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text=""
            android:layout_weight="1" />
    </LinearLayout>
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:id="@+id/llModel"
        android:layout_below="@+id/llBrand"
        android:weightSum="2"
        android:layout_weight="1"
        android:gravity="center" >
        <TextView
            android:id="@+id/tvModel"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="Phone Model: "
            android:layout_weight="1" />

        <TextView
            android:id="@+id/tvModelName"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text=""
            android:layout_weight="1" />
    </LinearLayout>
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:id="@+id/llVersion"
        android:layout_below="@+id/llModel"
        android:weightSum="2"
        android:layout_weight="1"
        android:gravity="center" >
        <TextView
            android:id="@+id/tvVersion"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="Android Version: "
            android:layout_weight="1" />

        <TextView
            android:id="@+id/tvVersionNumber"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text=""
            android:layout_weight="1" />
    </LinearLayout>
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:id="@+id/llCode"
        android:layout_below="@+id/llVersion"
        android:weightSum="2"
        android:layout_weight="1"
        android:gravity="center" >
        <TextView
            android:id="@+id/tvCode"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="Android Codename: "
            android:layout_weight="1" />

        <TextView
            android:id="@+id/tvCodeName"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text=""
            android:layout_weight="1" />
    </LinearLayout>
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:id="@+id/llAPI"
        android:layout_below="@+id/llCode"
        android:weightSum="2"
        android:layout_weight="1"
        android:gravity="center" >
        <TextView
            android:id="@+id/tvAPI"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="API Level: "
            android:layout_weight="1" />

        <TextView
            android:id="@+id/tvAPILevel"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text=""
            android:layout_weight="1" />
    </LinearLayout>
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:id="@+id/llScreen"
        android:layout_below="@+id/llAPI"
        android:weightSum="2"
        android:layout_weight="1"
        android:gravity="center" >
        <TextView
            android:id="@+id/tvScreen"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="Screen Size (WxH): "
            android:layout_weight="1" />

        <TextView
            android:id="@+id/tvScreenSize"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text=""
            android:layout_weight="1" />
    </LinearLayout>
    </LinearLayout>
</LinearLayout>

它显示以下内容:

在此处输入图像描述

我希望使徽标从顶部占据屏幕的 1/4,其余信息应占屏幕的 3/4。但由于某种原因,它们都聚集在一起。我该如何解决?

我想做以下(粗略的草图):

在此处输入图像描述

4

2 回答 2

1

I am looking to make the logo take up 1/4 of the screen from top and the rest of the information should be 3/4 of the screen

You need to do the following. Remove the attribute android:weightSum from llBottom, set android:layout_weight to 1 in llPhone, set android:layout_weight to 3 in llPhoneInfo.

The total sume of the weights will be 4, llPhone will take up 1/4 of the screen and llPhoneInfo will take up 3/4 of the screen.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/llBottom"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/llPhone"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="horizontal" >

        <ImageView ... />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/llPhoneInfo"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="3"
        android:gravity="center"
        android:orientation="vertical"
        android:weightSum="6" >

        ...    

   </LinearLayout>

</LinearLayout>

Do a similar calculation for the other layouts.

You should also consider using a RelativeLayout instead of several nested LinearLayouts for better performance.

于 2013-10-22T00:55:33.923 回答
1

这里有很多代码重复。在我看来,您应该只有一个带有 ImageView 和 listView 的线性布局。对线性布局内的两个子视图和以编程方式使用布局权重。有很多很好的教程来设置自定义列表视图。这个涵盖了您需要的一切。安卓列表视图

于 2013-10-22T00:22:30.930 回答