时间:2016-09-27 00:12:34

标签: android android-layout

让我们从我为这个问题做准备的截图开始

1 enter image description here

在这种布局中,也许大横幅不存在,所以它隐藏在你看到的另一张图片中。 这个布局的一部分包含一个文本,所以我想一起滚动内容,但我希望文本下的背景高度填充我的屏幕并且不影响滚动,因此当文本太长或横幅时滚动必须处于活动状态身高更大。

这是我的布局代码:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context=".NewsActivity"
    tools:showIn="@layout/activity_news">
<LinearLayout
    android:layout_width="match_parent"
    android:orientation="vertical"

    android:layout_height="wrap_content">
    <ImageView
        android:id="@+id/bigPicture"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:contentDescription="@null"
        android:scaleType="fitXY"
        android:src="@drawable/tama_logo" />


    <RelativeLayout
        android:fillViewport="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <de.hdodenhof.circleimageview.CircleImageView
            android:id="@+id/largeIcon"
            android:layout_width="48dp"
            android:layout_height="48dp"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="false"
            android:layout_alignWithParentIfMissing="false"
            android:src="@mipmap/ic_launcher"
            android:layout_marginTop="8dp"
            android:layout_marginRight="12dp"
            android:layout_marginLeft="8dp" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:padding="8dp"
                android:background="@drawable/shadow"

                android:id="@+id/messageBody"
                android:layout_toStartOf="@+id/largeIcon"
                android:layout_toLeftOf="@+id/largeIcon">

                <TextView
                    android:id="@+id/title"
                    style="@style/news_activity_title"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:ellipsize="end"
                    android:maxLines="2" />

                <TextView
                    android:id="@+id/body"
                    style="@style/news_activity_body"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:ellipsize="end"
                    android:maxLines="2" />
            </LinearLayout>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/date"
            android:layout_alignWithParentIfMissing="true"
            android:maxLines="3"
            android:text="1369/12/25 22:45:32"
            android:textColor="#aaa"
            android:textSize="10sp"
            android:singleLine="false"
            android:gravity="center_horizontal"
            android:textStyle="bold"
            android:layout_below="@+id/largeIcon"
            android:layout_toRightOf="@+id/messageBody"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true"
            android:layout_marginRight="5dp" />

    </RelativeLayout>
</LinearLayout>
</ScrollView>

这张照片将解释我的期望,对不起我的坏英语:(

enter image description here

1 个答案:

答案 0 :(得分:1)

检查以下代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:fillViewport="true"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <ImageView
            android:id="@+id/bigPicture"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:contentDescription="@null"
            android:scaleType="fitXY"
            android:src="@drawable/tama_logo" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal"
            android:weightSum="6">


            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="4"
                android:background="@android:color/white">

                <TextView
                    android:id="@+id/title"
                    style="@style/news_activity_title"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_alignParentRight="true"
                    android:layout_alignParentTop="true"
                    android:ellipsize="end"
                    android:maxLines="2" />

                <TextView
                    android:id="@+id/body"
                    style="@style/news_activity_body"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_alignParentRight="true"
                    android:layout_below="@+id/title"
                    android:ellipsize="end"
                    android:maxLines="2" />


            </RelativeLayout>


            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="2">

                <de.hdodenhof.circleimageview.CircleImageView
                    android:id="@+id/largeIcon"
                    android:layout_width="48dp"
                    android:layout_height="48dp"
                    android:layout_alignParentEnd="true"
                    android:layout_alignParentRight="true"
                    android:layout_alignParentTop="false"
                    android:layout_alignWithParentIfMissing="false"
                    android:layout_marginLeft="8dp"
                    android:layout_marginRight="12dp"
                    android:layout_marginTop="8dp"
                    android:src="@mipmap/ic_launcher" />


                <TextView
                    android:id="@+id/date"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentEnd="true"
                    android:layout_alignParentRight="true"
                    android:layout_alignWithParentIfMissing="true"
                    android:layout_below="@+id/largeIcon"
                    android:layout_marginRight="5dp"
                    android:gravity="center_horizontal"
                    android:maxLines="3"
                    android:singleLine="false"
                    android:text="1369/12/25 22:45:32"
                    android:textColor="#aaa"
                    android:textSize="10sp"
                    android:textStyle="bold" />

            </RelativeLayout>


        </LinearLayout>
    </ScrollView>
</LinearLayout>

希望它有所帮助。

相关问题