在ScrollView内创建LinearLayout

时间:2018-10-11 06:51:13

标签: android android-layout android-linearlayout android-scrollview

我尝试创建下面的image。但是由于某种原因,我的image不在screen的顶部,而我的text却不在彼此的下方。我将如何解决这个问题?由于我是Android新手。

我想在图片下方实现什么

enter image description here

下面的代码

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

1 个答案:

答案 0 :(得分:0)

1)将android:fillViewport="true"添加到ScrollView

2)玩<Space />

<?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"
    android:fillViewport="true">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:orientation="vertical">
        <Space
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_weight="1"/>
        <ImageView
            android:layout_gravity="center"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@android:drawable/ic_delete"/>


        <Space
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_weight="1"/>
        .
        .
        .

        <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"/>


        <Space
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_weight="1"/>
    </LinearLayout>

</ScrollView>