2017-03-05 30 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でパディングを使用しています。パディングは必要な場所に余裕を持たせています。デザインのために、2つの異なるビューのように見えるようにすることができます。 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

関連する問題