1

I'm using NavigationDrawer and some fragments. I maked a simple example with an AutoCompleteTextView, but the width don't stretch with the screen size.

Code of fragment.java:

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle         savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_bestplaces, container,   false);
    return rootView;
}

Code of fragment.xml:

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

       <LinearLayout
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:orientation="vertical"
          android:paddingBottom="16dp"
          android:paddingLeft="16dp"
          android:paddingRight="16dp"
          android:paddingTop="16dp">

          <AutoCompleteTextView
             android:id="@+id/autocomplete_find"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:layout_gravity="center_horizontal"
             android:hint="Search"
             android:singleLine="true" />

          <Button
             android:id="@+id/button_find"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_gravity="center_horizontal"
             android:text="Find" />

      </LinearLayout>
  </ScrollView>

In design it's ok, but when i run the app it's wrong:

Design Image

Running Image

Someone can help me?

Cassiano
  • 125
  • 1
  • 7

3 Answers3

0

You are using padding in the LinearLayout. Padding makes room where you need it, and for design it can be used to make views look clearly like two different, and not like they have fused together. Remove this code from the LinearLayout:

android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
Zoe
  • 27,060
  • 21
  • 118
  • 148
0

I suspect it is because of fill_parent in the LinearLayout.

      android:layout_width="fill_parent"
      android:layout_height="fill_parent"

Because fill_parent is deprecated. I recommend to change it match_parent.

Shreyash S Sarnayak
  • 2,309
  • 19
  • 23
0

May be the problem of your container layout, can you show the layout file of your fragment container.

  • You're right my friend. In fragment container the was defined as wrap_content. **I changed to match_parent** and now it's working fine. Thanks! – Cassiano Mar 05 '17 at 15:51