アンドロイドStudioでスクロール可能なコンテンツを設計する際に従うための方法は何ですか?

アーロンDCosta:

私は、制約レイアウトで私のアプリを設計していると私は、スクロールビューの下に置いています。私はより多くのカードビューを配置したいが、xmlファイルのプレビューでそうする場所がありません。レイアウトがいっぱいになったとき、私はどこをドラッグしないとボタンをドロップし、TextViewsなど?私は、テキストのスクロールビューを扱ってきたが、これは何か他のものです。

私は単にコードを入力できることを承知していますが、私は内容が定義された画面サイズで出ているように私は私が設計しています正確に何を見ることができるように文句を言わないときにそれを行うことは難しいでしょう。

(あなたは私がより良い質問を理解するためにスクリーンショットを投稿したい場合は、私がコメントで知らせてください)

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/images"
    android:fillViewport="true"
    >
<androidx.constraintlayout.widget.ConstraintLayout
    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"
    android:background="@drawable/images"
    tools:context=".MainActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="vertical"
        app:layout_constraintBottom_toBottomOf="parent"
        tools:layout_editor_absoluteX="10dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:clipToPadding="false"
            android:gravity="center"
            android:orientation="horizontal">

            <androidx.cardview.widget.CardView
                android:id="@+id/test_donation"
                android:layout_width="160dp"
                android:layout_height="190dp"
                android:layout_margin="10dp"
                android:clickable="true"
                android:foreground="?android:attr/selectableItemBackground"
                android:padding="0dp">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="#660000"
                    android:gravity="center"
                    android:orientation="vertical">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="130dp"
                        android:background="#660000"
                        android:gravity="center">

                        <ImageView
                            android:layout_width="80dp"
                            android:layout_height="80dp"
                            android:padding="10dp"
                            android:src="@drawable/ic_donate" />
                    </LinearLayout>

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="DONATE"
                        android:textColor="#FFEb3b"
                        android:textSize="24sp" />

                </LinearLayout>
            </androidx.cardview.widget.CardView>

            <androidx.cardview.widget.CardView
                android:id="@+id/test_receive"
                android:layout_width="160dp"
                android:layout_height="190dp"
                android:layout_margin="10dp"
                android:clickable="true"
                android:foreground="?android:attr/selectableItemBackground"
                android:padding="0dp">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="#660000"
                    android:gravity="center"
                    android:orientation="vertical">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="130dp"
                        android:background="#660000"
                        android:gravity="center">

                        <ImageView
                            android:layout_width="80dp"
                            android:layout_height="80dp"
                            android:padding="10dp"
                            android:src="@drawable/ic_receive" />
                    </LinearLayout>

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="RECEIVE"
                        android:textColor="#FFEb3b"
                        android:textSize="24sp" />

                </LinearLayout>
            </androidx.cardview.widget.CardView>

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:clipToPadding="false"
            android:gravity="center"
            android:orientation="horizontal">

            <androidx.cardview.widget.CardView
                android:id="@+id/test_chat"
                android:layout_width="160dp"
                android:layout_height="190dp"
                android:layout_margin="10dp"
                android:clickable="true"
                android:foreground="?android:attr/selectableItemBackground"
                android:padding="0dp">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="#660000"
                    android:gravity="center"
                    android:orientation="vertical">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="130dp"
                        android:background="#660000"
                        android:gravity="center">

                        <ImageView
                            android:layout_width="80dp"
                            android:layout_height="80dp"
                            android:padding="10dp"
                            android:src="@drawable/ic_chat" />
                    </LinearLayout>

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="CHAT"
                        android:textColor="#FFEb3b"
                        android:textSize="24sp" />

                </LinearLayout>
            </androidx.cardview.widget.CardView>

            <androidx.cardview.widget.CardView
                android:id="@+id/test_logout"
                android:layout_width="160dp"
                android:layout_height="190dp"
                android:layout_margin="10dp"
                android:clickable="true"
                android:foreground="?android:attr/selectableItemBackground"
                android:padding="0dp">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="#660000"
                    android:gravity="center"
                    android:orientation="vertical">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="130dp"
                        android:background="#660000"
                        android:gravity="center">

                        <ImageView
                            android:layout_width="80dp"
                            android:layout_height="80dp"
                            android:padding="10dp"
                            android:src="@drawable/ic_logout" />
                    </LinearLayout>

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="LOGOUT"
                        android:textColor="#FFEb3b"
                        android:textSize="24sp" />

                </LinearLayout>
            </androidx.cardview.widget.CardView>

        </LinearLayout>
    </LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
鉄人 :

まあ、私はあなたがより多くの追加だけにしようとしていないと思いCardViewS(またはその他View複数可)...私はあなたのコードの逓倍量をコピーしたCardViews、そしてそれは魔法のように働いた...ここに私のために働いていたものです:

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

    <androidx.constraintlayout.widget.ConstraintLayout 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"
        tools:context=".MainActivity">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:orientation="vertical"
            app:layout_constraintBottom_toBottomOf="parent"
            tools:layout_editor_absoluteX="10dp">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:clipToPadding="false"
                android:gravity="center"
                android:orientation="horizontal">

                <androidx.cardview.widget.CardView
                    android:id="@+id/test_donation"
                    android:layout_width="160dp"
                    android:layout_height="190dp"
                    android:layout_margin="10dp"
                    android:clickable="true"
                    android:foreground="?android:attr/selectableItemBackground"
                    android:padding="0dp">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:background="#660000"
                        android:gravity="center"
                        android:orientation="vertical">

                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="130dp"
                            android:background="#660000"
                            android:gravity="center">

                            <ImageView
                                android:layout_width="80dp"
                                android:layout_height="80dp"
                                android:padding="10dp" />
                        </LinearLayout>

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="DONATE"
                            android:textColor="#FFEb3b"
                            android:textSize="24sp" />

                    </LinearLayout>
                </androidx.cardview.widget.CardView>

                <androidx.cardview.widget.CardView
                    android:id="@+id/test_receive"
                    android:layout_width="160dp"
                    android:layout_height="190dp"
                    android:layout_margin="10dp"
                    android:clickable="true"
                    android:foreground="?android:attr/selectableItemBackground"
                    android:padding="0dp">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:background="#660000"
                        android:gravity="center"
                        android:orientation="vertical">

                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="130dp"
                            android:background="#660000"
                            android:gravity="center">

                            <ImageView
                                android:layout_width="80dp"
                                android:layout_height="80dp"
                                android:padding="10dp" />
                        </LinearLayout>

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="RECEIVE"
                            android:textColor="#FFEb3b"
                            android:textSize="24sp" />

                    </LinearLayout>
                </androidx.cardview.widget.CardView>

            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:clipToPadding="false"
                android:gravity="center"
                android:orientation="horizontal">

                <androidx.cardview.widget.CardView
                    android:id="@+id/test_chat"
                    android:layout_width="160dp"
                    android:layout_height="190dp"
                    android:layout_margin="10dp"
                    android:clickable="true"
                    android:foreground="?android:attr/selectableItemBackground"
                    android:padding="0dp">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:background="#660000"
                        android:gravity="center"
                        android:orientation="vertical">

                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="130dp"
                            android:background="#660000"
                            android:gravity="center">

                            <ImageView
                                android:layout_width="80dp"
                                android:layout_height="80dp"
                                android:padding="10dp" />
                        </LinearLayout>

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="CHAT"
                            android:textColor="#FFEb3b"
                            android:textSize="24sp" />

                    </LinearLayout>
                </androidx.cardview.widget.CardView>

                <androidx.cardview.widget.CardView
                    android:id="@+id/test_logout"
                    android:layout_width="160dp"
                    android:layout_height="190dp"
                    android:layout_margin="10dp"
                    android:clickable="true"
                    android:foreground="?android:attr/selectableItemBackground"
                    android:padding="0dp">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:background="#660000"
                        android:gravity="center"
                        android:orientation="vertical">

                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="130dp"
                            android:background="#660000"
                            android:gravity="center">

                            <ImageView
                                android:layout_width="80dp"
                                android:layout_height="80dp"
                                android:padding="10dp" />
                        </LinearLayout>

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="LOGOUT"
                            android:textColor="#FFEb3b"
                            android:textSize="24sp" />

                    </LinearLayout>
                </androidx.cardview.widget.CardView>

            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:clipToPadding="false"
                android:gravity="center"
                android:orientation="horizontal">

                <androidx.cardview.widget.CardView
                    android:id="@+id/test_chat_other"
                    android:layout_width="160dp"
                    android:layout_height="190dp"
                    android:layout_margin="10dp"
                    android:clickable="true"
                    android:foreground="?android:attr/selectableItemBackground"
                    android:padding="0dp">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:background="#660000"
                        android:gravity="center"
                        android:orientation="vertical">

                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="130dp"
                            android:background="#660000"
                            android:gravity="center">

                            <ImageView
                                android:layout_width="80dp"
                                android:layout_height="80dp"
                                android:padding="10dp" />
                        </LinearLayout>

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="CHAT"
                            android:textColor="#FFEb3b"
                            android:textSize="24sp" />

                    </LinearLayout>
                </androidx.cardview.widget.CardView>

                <androidx.cardview.widget.CardView
                    android:id="@+id/test_other"
                    android:layout_width="160dp"
                    android:layout_height="190dp"
                    android:layout_margin="10dp"
                    android:clickable="true"
                    android:foreground="?android:attr/selectableItemBackground"
                    android:padding="0dp">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:background="#660000"
                        android:gravity="center"
                        android:orientation="vertical">

                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="130dp"
                            android:background="#660000"
                            android:gravity="center">

                            <ImageView
                                android:layout_width="80dp"
                                android:layout_height="80dp"
                                android:padding="10dp" />
                        </LinearLayout>

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="LOGOUT"
                            android:textColor="#FFEb3b"
                            android:textSize="24sp" />

                    </LinearLayout>
                </androidx.cardview.widget.CardView>
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:clipToPadding="false"
                android:gravity="center"
                android:orientation="horizontal">

                <androidx.cardview.widget.CardView
                    android:id="@+id/test_chat_other_"
                    android:layout_width="160dp"
                    android:layout_height="190dp"
                    android:layout_margin="10dp"
                    android:clickable="true"
                    android:foreground="?android:attr/selectableItemBackground"
                    android:padding="0dp">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:background="#660000"
                        android:gravity="center"
                        android:orientation="vertical">

                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="130dp"
                            android:background="#660000"
                            android:gravity="center">

                            <ImageView
                                android:layout_width="80dp"
                                android:layout_height="80dp"
                                android:padding="10dp" />
                        </LinearLayout>

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="CHAT"
                            android:textColor="#FFEb3b"
                            android:textSize="24sp" />

                    </LinearLayout>
                </androidx.cardview.widget.CardView>

                <androidx.cardview.widget.CardView
                    android:id="@+id/test_other_"
                    android:layout_width="160dp"
                    android:layout_height="190dp"
                    android:layout_margin="10dp"
                    android:clickable="true"
                    android:foreground="?android:attr/selectableItemBackground"
                    android:padding="0dp">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:background="#660000"
                        android:gravity="center"
                        android:orientation="vertical">

                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="130dp"
                            android:background="#660000"
                            android:gravity="center">

                            <ImageView
                                android:layout_width="80dp"
                                android:layout_height="80dp"
                                android:padding="10dp" />
                        </LinearLayout>

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="LOGOUT"
                            android:textColor="#FFEb3b"
                            android:textSize="24sp" />

                    </LinearLayout>
                </androidx.cardview.widget.CardView>
            </LinearLayout>

        </LinearLayout>
    </androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>

私はそれらのSRCを持っていないので、それはスクリーンと軍から外れていると、さらに4枚のカードと、画像のみなしで、あなたがやったとちょうど同じだScrollViewsが有効になっているスクロール...あなたがしようとした場合にもかかわらず、特定の空間でそれを行う、あなただけに固有の高さを設定する必要がありScrollView、そしてmatch_parentありません。とにかく、ScrollViewそれはどのようなスクロールをしているときにのみスクロールが(もちろん、あなただけのカードを使用する必要はありません...あなたはに何かを追加することができScrollView、そして何かがその境界から外れたときに、そのスクロールが作動し)

私はそれが役に立てば幸い!

おすすめ

転載: http://10.200.1.11:23101/article/api/json?id=477333&siteId=1