2017-03-05 136 views
1

我正在使用NavigationDrawer和一些片段。我用一个AutoCompleteTextView制作了一个简单的例子,但宽度不能随着屏幕尺寸拉伸。Android片段布局的宽度错误

代码fragment.java的:

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

代码:

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

在设计它的确定,但是当我运行应用程序时它是错误的:

Design Image

Running Image

有人可以帮助我吗?

回答

0

可能是你的容器布局的问题,你可以显示你的碎片容器的布局文件。

+0

你是对的我的朋友。在片段容器中,被定义为wrap_content。 **我改为match_parent **,现在工作正常。谢谢! – Cassiano

0

您在LinearLayout中使用了填充。填充可以在需要的地方留出空间,并且可以用于设计,使得视图看起来像两个不同的视图,而不像它们融合在一起。从LinearLayout中删除此代码:

android:paddingBottom="16dp" 
android:paddingLeft="16dp" 
android:paddingRight="16dp" 
android:paddingTop="16dp" 
0

我怀疑这是因为在LinearLayoutfill_parent

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

因为fill_parent已被弃用。我建议改变它match_parent