【发布时间】:2020-05-18 00:01:09
【问题描述】:
我正在使用约束布局设计我的应用程序,并将其放置在滚动视图下。我想放置更多卡片视图,但在 xml 文件的预览中没有地方这样做。当布局已满时,我在哪里拖放按钮、TextViews 等?我已经处理了文本的滚动视图,但这是另一回事。
我知道我可以只输入代码,但是当我无法看到我正在设计的具体内容时,我将很难这样做,因为内容超出了定义的屏幕尺寸。
(如果您希望我发布屏幕截图以更好地理解问题,请在 cmets 中告诉我)
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>
【问题讨论】:
-
请发截图,我看不懂问题:/
-
i.stack.imgur.com/YPulN.jpg 在这里,我想添加更多的卡片视图,而不是可以向上滚动用户的 4 个卡片视图,但正如您所见,没有地方可以拖放它们。 (我希望整个活动都是可滚动的,而不仅仅是卡片视图,这就是 XML 文件的根布局是 Scroll View 的原因)
标签: java android xml android-layout scrollview