2017-03-05 176 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