【问题标题】:HorizontalScrollView fill entire screen with ScrollViewHorizo​​ntalScrollView 用 ScrollView 填满整个屏幕
【发布时间】:2013-06-13 07:36:42
【问题描述】:

我正在使用 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 的一部分仍然可见,以便用户知道它是可滚动的?

【问题讨论】:

  • 线性布局在垂直ScrollView 内,因此高度不会是match_parent,而是wrap_content,水平滚动视图也会将换行内容作为高度。如果您想让用户知道他可以滚动,您可以使用淡入淡出效果和/或滚动条。对于淡入淡出效果,您可以使用android:requiresFadingEdge="vertical"(或类似的东西),您还可以设置淡入淡出的边缘大小

标签: android android-layout


【解决方案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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-12
    • 1970-01-01
    • 2015-06-06
    • 1970-01-01
    相关资源
    最近更新 更多