Создайте LinearLayout внутри ScrollView - PullRequest
0 голосов
/ 11 октября 2018

Я попытался создать 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 голосов
/ 11 октября 2018

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