android - Horizo​​ntalScrollView 用 ScrollView 填满整个屏幕

标签 android android-layout

我正在使用具有 Horizo​​ntalScrollView 和一些 EditTextScrollView 创建布局。它看起来像下图。

enter image description here

到目前为止我的代码如下

<?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 不工作.. 有什么方法可以让 Horizo​​ntalScrollView 填满整个屏幕,同时某些 TextView 仍然可见,以便用户知道它可以滚动吗?

最佳答案

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

<?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>

关于android - Horizo​​ntalScrollView 用 ScrollView 填满整个屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17081649/

相关文章:

android - 发布新版本的安卓应用

android - 如何在 Android 中的框架布局上显示可扩展布局?

android - useOldManifestMerger 导致构建错误

android - 在两个 fragment 之间拖放?

android - 如何使用 staggeredGridLayoutManager 将 headerview 添加到 recyclerview

java - 嵌套 findViewById

android - Android 中的 SwiperefreshLayout

java - 在 android 中使用 android-support-v7-appcompat 库运行 PopupMenu 时出现 NoClassDefFoundError

Android Studio 模拟器尺寸与真实尺寸不符

android - 在android中加载flash文件(.swf)webview