Search code examples
androidxmlandroid-layoutlayoutandroid-wrap-content

Cannot show all the content using wrap_content in Android


Can anyone explain to me why I can't show the content of address using the following XML code. Thank you so much in advance. The content should be more than 3 lines, but only two lines of content are showed when I execute the program.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#e6e6e6"
android:orientation="vertical"
android:padding="1dp">

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">



        <TextView

            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="#868585"
            android:padding="0dp"
            android:text="Basic Information"
            android:textColor="#ffffff" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="9"
                    app:srcCompat="@drawable/navigation" />

                <TextView
                    android:id="@+id/textView7"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:text="Address" />
            </LinearLayout>


            <View
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="@android:color/darker_gray" />


        </LinearLayout>


    </LinearLayout>
</ScrollView>


Solution

  • your all control not visible due scroll view because scroll view can haldle direct one child try to make your layout like this

        <ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">
    
     <LinearLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="vertical">   
    
    
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="#868585"
            android:padding="0dp"
            android:text="Basic Information"
            android:textColor="#ffffff" />
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">
    
                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="9"
                    app:srcCompat="@drawable/navigation" />
    
                <TextView
                    android:id="@+id/textView7"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="Address" />
            </LinearLayout>
    
    
            <View
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="@android:color/darker_gray" />
    
    
        </LinearLayout>
    
    </LinearLayout>
    
    </ScrollView>