2

我正在用ScrollView那个HorizontalScrollView和一些EditText..创建布局。它看起来像下面的图像..

在此处输入图像描述

到目前为止,我的代码如下

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:fillViewport="true"
    >

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


    <HorizontalScrollView
            android:id="@+id/mainHorizontalScrollView"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            >

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

            <ImageView
                    android:id="@+id/image1"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:scaleType="fitXY"
                    android:src="@drawable/pic1"
                    android:padding="15dp"
                    ></ImageView>

            <ImageView
                    android:id="@+id/image2"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:scaleType="fitXY"
                    android:src="@drawable/pic2"
                    android:padding="15dp"
                    ></ImageView>

            <ImageView
                    android:id="@+id/image3"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:scaleType="fitXY"
                    android:src="@drawable/pic3"
                    android:padding="15dp"
                    ></ImageView>

        </LinearLayout>

    </HorizontalScrollView>

    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/textViewPrice"
            />

    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/textViewDetail"
            />

</LinearLayout>
</ScrollView>

我上面的代码使ScrollView不工作..有没有办法让HorizontalScrollView填充整个屏幕,而其中一些TextView仍然可见,以便用户知道它的可滚动?

4

1 回答 1

1

这是我的代码。它对我有用。

<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView  xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:scrollbars="none" >
    <LinearLayout
        android:id="@+id/casts_container"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="5dp"
        android:layout_marginTop="5dp"
        android:gravity="center_vertical"
        android:orientation="horizontal">
        <android.support.v7.widget.CardView
            android:layout_width="345dp"
            android:layout_height="wrap_content"
            android:layout_margin="8dp">
            <ScrollView
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">
                    <ImageView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:src="@drawable/image" />
                    <ImageView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:src="@drawable/image" />
                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:gravity="center"
                        android:text="for demo purpose"
                        android:textSize="50dp" />
                    <ImageView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:src="@drawable/image" />
                    <ImageView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:src="@drawable/image" />
                </LinearLayout>
            </ScrollView>
        </android.support.v7.widget.CardView>
        <android.support.v7.widget.CardView
            android:layout_width="345dp"
            android:layout_height="wrap_content"
            android:layout_margin="8dp">
            <ScrollView
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">
                    <ImageView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:src="@drawable/image" />
                    <ImageView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:src="@drawable/image" />
                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:gravity="center"
                        android:text="for demo purpose"
                        android:textSize="50dp" />
                    <ImageView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:src="@drawable/image" />
                    <ImageView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:src="@drawable/image" />
                </LinearLayout>
            </ScrollView>
        </android.support.v7.widget.CardView>
        <android.support.v7.widget.CardView
            android:layout_width="345dp"
            android:layout_height="wrap_content"
            android:layout_margin="8dp">
            <ScrollView
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">
                    <ImageView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:src="@drawable/image" />
                    <ImageView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:src="@drawable/image" />
                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:gravity="center"
                        android:text="for demo purpose"
                        android:textSize="50dp" />
                    <ImageView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:src="@drawable/image" />
                    <ImageView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:src="@drawable/image" />
                </LinearLayout>
            </ScrollView>
        </android.support.v7.widget.CardView>
    </LinearLayout>
</HorizontalScrollView>
于 2018-07-02T18:43:24.667 回答