Abhishek Kumar Abhishek Kumar - 3 months ago 6
Android Question

match_parent doesn't fill the desired result

only white portion is taken and that too after taking match_parent


I've been trying to add this layout . everything works fine . I want the second edittext to take all the rest height of the layout . i've made this edittext as match_parent but it can't take all the space,.
can somebody tell me the problem i'm having ?


<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">


<LinearLayout xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
android:id="@+id/createxml_layout_id">

<EditText
android:id="@+id/createxml_title_id"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scrollHorizontally="true"
android:hint="Title"
android:textAlignment="center"
android:textColor="#000"
android:textAllCaps="true"
android:textSize="20sp"
android:maxLength="20"
android:autoText="false"
android:inputType="textPersonName"
android:gravity="fill_horizontal"
android:textAppearance="?android:attr/textAppearanceMedium" />

<EditText
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:hint="CONTENT HERE"
android:id="@+id/createxml_content_id"
android:textSize="14sp"
android:layout_gravity="top"/>

<android.support.design.widget.FloatingActionButton

android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
app:fabSize="mini"
android:layout_margin="10dp"
android:src="@android:drawable/ic_dialog_email" >

</android.support.design.widget.FloatingActionButton>

<!--</LinearLayout>-->

</LinearLayout>

</ScrollView>

Answer

Use android:fillViewport="true" in your scroll view it will fill up the screen.And in your xml you set weight on edit-text but doesn't set weight sum on parent layout.Set weight-sum on linear layout.

 <?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true"
    xmlns:app="http://schemas.android.com/apk/res-auto">


    <LinearLayout xmlns:tools="http://schemas.android.com/tools"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#fff"
        android:weightSum="2"
        android:id="@+id/createxml_layout_id">

        <EditText
            android:id="@+id/createxml_title_id"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:scrollHorizontally="true"
            android:hint="Title"
            android:textAlignment="center"
            android:textColor="#000"
            android:textAllCaps="true"
            android:textSize="20sp"
            android:maxLength="20"
            android:autoText="false"
            android:inputType="textPersonName"
            android:gravity="fill_horizontal"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <EditText
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:hint="CONTENT HERE"
            android:id="@+id/createxml_content_id"
            android:textSize="14sp"
            android:layout_gravity="top"/>

        <android.support.design.widget.FloatingActionButton

            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|end"
            app:fabSize="mini"
            android:layout_margin="10dp"
            android:src="@android:drawable/ic_dialog_email" >

        </android.support.design.widget.FloatingActionButton>

        <!--</LinearLayout>-->

      </LinearLayout>

     </ScrollView>
Comments