Android滚动视图图像和文本

时间:2013-12-03 15:19:57

标签: android scrollview

我正在一个滚动视图中解决图像和文本的问题。主要问题是,我从服务器端获得不同的图像高度。但是有图像的地方应该一直都是一样的。 现在图像的高度是动态的。文本应该可以与图像一起滚动。

是否有可能如何使图像高度保持静止?

谢谢!

enter image description here

修改

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

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <RelativeLayout
            android:id="@+id/article_gallery"
            android:layout_width="match_parent"
            android:layout_height="0dip"
            android:layout_weight="4" >

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

                <ImageView
                    android:id="@+id/article_image_back"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:src="@drawable/sipka_l" />

                <ImageView
                    android:id="@+id/article_image"
                    android:layout_width="0dip"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_weight="1" />

                <ImageView
                    android:id="@+id/article_image_next"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:src="@drawable/sipka_p" />
            </LinearLayout>

            <TextView
                android:id="@+id/image_desc"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:background="@color/tran_dark_gray"
                android:gravity="center"
                android:padding="@dimen/size_8"
                android:textAppearance="@style/xsmallLight" />
        </RelativeLayout>

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="0dip"
            android:layout_weight="6"
            android:background="@color/opaq_light"
            android:orientation="horizontal" >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:padding="@dimen/size_16" >

                <TextView
                    android:id="@+id/article_title"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:paddingBottom="@dimen/size_12"
                    android:textAppearance="@style/normalBold" />

                <TextView
                    android:id="@+id/article_body"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textAppearance="@style/xsmall" />
            </LinearLayout>
        </ScrollView>
    </LinearLayout>
</FrameLayout>

2 个答案:

答案 0 :(得分:0)

如果声明ImageView具有固定的宽度和高度,它将始终保持静态。

尝试类似:

 <ImageView
        android:id="@+id/imageView1"
        android:layout_width="50dp"
        android:layout_height="50dp"
/>

将此ImageView放在ScrollView内,并将您的TextView放在同一个ScrollView中。

答案 1 :(得分:0)

您可以为linearlayout使用布局权重。将宽度设置为0并让重量确定实际尺寸。将重量设置为0.33,每个图像为屏幕的1/3。 或者你可以将一个设置为0.5,将其他设置为0.25或者对应用程序有意义的任何内容。

将3张图像设为:

      <ImageView
           android:id="@+id/article_image_back"
           android:layout_width="0dp"
           android:layout_height="wrap_content"
           android:layout_weight="0.33"
           android:layout_gravity="center_vertical"
           android:src="@drawable/sipka_l" />