2

我想显示一半屏幕的图像视图和屏幕的其余部分我将显示多个这样的文本视图

在此处输入图像描述

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="fill_parent"
     android:layout_height="?android:attr/listPreferredItemHeight"

     android:padding="6dip">

     <ImageView
        android:id="@+id/icon"

        android:layout_width="wrap_content"
        android:layout_height="fill_parent"

        android:layout_alignParentTop="true"
        android:layout_alignParentBottom="true"
        android:layout_marginRight="6dip"

        android:src="@drawable/icon" />

    <TextView  
        android:id="@+id/secondLine"

        android:layout_width="fill_parent"
        android:layout_height="26dip" 

        android:layout_toRightOf="@id/icon"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"

        android:singleLine="true"
        android:ellipsize="marquee"
        android:text="Simple application that shows how to use RelativeLayout" />

     <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"

        android:layout_toRightOf="@id/icon"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_above="@id/secondLine"
        android:layout_alignWithParentIfMissing="true"

        android:gravity="center_vertical"
        android:text="My Application" />

     </RelativeLayout>
4

5 回答 5

2

您需要使用权重概念

下面是代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="10" >

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="5" >

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <!-- put your imagebackground image -->

</LinearLayout>

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="5"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="5"
        android:gravity="center"
        android:weightSum="1" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight=".33"
            android:text="firstText" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="5"
        android:gravity="center"
        android:weightSum="1" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight=".33"
            android:text="secondText" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="5"
        android:gravity="center"
        android:weightSum="1" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight=".33"
            android:text="thirdText" />
    </LinearLayout>
</LinearLayout>

于 2013-10-28T13:10:20.757 回答
1

而不是相对布局,使用 LinearLayout 并使用 weightsum 属性。

样本,

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="?android:attr/listPreferredItemHeight"
    android:weightSum="2"
    android:orientation="horizontal">



    <ImageView
        android:id="@+id/icon"
        android:layout_width="0dip"
        android:layout_height="fill_parent"
        android:layout_alignParentBottom="true"
        android:layout_alignParentTop="true"
        android:layout_marginRight="6dip"
        android:layout_weight="1"
        android:src="@drawable/icon" />


    <LinearLayout android:layout_width="0dip"
        android:orientation="vertical"
        android:layout_height="fill_parent"
        android:layout_weight="1">

    <TextView
        android:id="@+id/secondLine"
        android:layout_width="fill_parent"
        android:layout_height="26dip"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_toRightOf="@id/icon"
        android:ellipsize="marquee"
        android:singleLine="true"
        android:text="Simple application that shows how to use RelativeLayout" />

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@id/secondLine"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_alignWithParentIfMissing="true"
        android:layout_toRightOf="@id/icon"
        android:gravity="center_vertical"
        android:text="My Application" />
</LinearLayout>
    </LinearLayout>
于 2013-10-28T13:00:52.547 回答
0

这对我有用:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:orientation="horizontal"
android:padding="6dip" >

<ImageView
    android:id="@+id/icon"
    android:layout_width="150dip"
    android:layout_height="fill_parent"
    android:layout_alignParentBottom="true"
    android:layout_alignParentTop="true"
    android:layout_marginRight="6dip"
    android:src="@drawable/icon" />

<LinearLayout 
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent">

<TextView
    android:id="@+id/secondLine"
    android:layout_width="fill_parent"
    android:layout_height="26dip"
    android:ellipsize="marquee"
    android:singleLine="true"
    android:text="Simple application that shows how to use RelativeLayout" />

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center_vertical"
    android:text="My Application" />

</LinearLayout>

于 2013-10-28T13:05:45.483 回答
0

将所有屏幕分为两部分首先是 imageview 和其他布局采用所有其他视图并设置 imageview 权重和其他布局权重 = 1 并采用高度填充父级

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >

<ImageView
    android:id="@+id/info"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:src="@drawable/ic_launcher"
    android:text="TextView" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1" >
</LinearLayout>

于 2013-10-28T13:01:47.200 回答
0

对父视图使用权重总和,并android:layout_weight="50"为第一个子布局实现,对另一个子布局也是如此......

于 2013-10-28T13:01:53.387 回答