【发布时间】:2018-10-11 06:51:13
【问题描述】:
我已尝试创建附在下面的image。但由于某种原因,我的image 不在screen 的顶部,而我的text 不在彼此下方。我将如何解决这个问题?因为我是安卓新手。
我想在下面的图片中实现什么
代码如下
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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:orientation="vertical"
android:background="@color/colorPrimary"
android:layout_gravity="center">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical">
<ImageView
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/solver"/>
<View
android:layout_marginTop="5dp"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Record phone calls"
android:textColor="@color/colorWhite"
android:layout_gravity="center"
android:textSize="18sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Know who viewed your profile"
android:textColor="@color/colorWhite"
android:layout_gravity="center"
android:textSize="18sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option to view profiles privately"
android:textColor="@color/colorWhite"
android:layout_gravity="center"
android:textSize="18sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Get the Premium badge on your profile"
android:textColor="@color/colorWhite"
android:layout_gravity="center"
android:textSize="18sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="30 contact requests a month"
android:layout_gravity="center"
android:textColor="@color/colorWhite"
android:textSize="18sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="No ads"
android:layout_gravity="center"
android:textColor="@color/colorWhite"
android:textSize="18sp"/>
</LinearLayout>
</LinearLayout>
<View
android:layout_marginTop="5dp"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Monthly Premium R19,19"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Yearly Premium R179,99"/>
</LinearLayout>
</ScrollView>
【问题讨论】:
-
首先将
android:fillViewPort="true"放入正确包含其子元素的ScrollView。根据您的设计使用ConstrainLayout或RelativeLayout而不是LinearLayout。 -
从线性布局和滚动视图中删除
android:layout_gravity="center"
标签: android android-layout android-linearlayout android-scrollview