2017-11-23 8 views
0

私は、リストビュー、編集テキストボックス、チュートリアルのオンラインで見つかったボタンからなるメッセージインターフェースを持っています。 XMLの実装では、テキストボックスとボタンの上のリストビューを完全にレイアウトしています。しかし、画面の上部にあるオーディオプレーヤーの2つのフラグメント(1)とメッセージングのための2つのフラグメント(1)を使用してレイアウトを実装しようとすると、テキストボックスとボタンを強制的にリストビューの下に表示できません。ビューやその他のUIアイテムをフラグメントレイアウトに配置するにはどうすればよいですか?

XMLは以下の通りです。 は、(1)期待どおりに動作:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation ="vertical" 
    tools:context=".MainActivity" 
    > 

    <ListView 
     android:id ="@+id/message_list" 
     android:layout_weight="100" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:divider="@null" 
     /> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <EditText 
      android:id="@+id/new_message" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="100" 
      android:inputType="text"> 
      <requestFocus /> 
     </EditText> 

     <Button 
      android:id="@+id/send_message" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="@color/colorPrimary" 
      android:text="@string/send_message" 
      android:textColor="@android:color/white" /> 

    </LinearLayout> 

</LinearLayout> 

(2)リストビューのトップのか、近くに上部のテキストとボタン体位:(2)リニアレイアウトに変更

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

     <ListView 
      android:id="@+id/message_list" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:divider="@null" /> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <EditText 
      android:id="@+id/new_message" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="100" 
      android:inputType="text" 
      android:labelFor="@id/new_message" /> 

     <Button 
      android:id="@+id/send_message" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="@color/colorPrimary" 
      android:text="@string/send_message" 
      android:textColor="@android:color/white" /> 

    </LinearLayout> 

</RelativeLayout> 

を私の問題は解決していません。

+0

2番目のレイアウトに複数の問題があります。あなたはandroid:orientation = "vertical"をrelativelayoutで使うことはできません。 – PrisonMike

+0

ありがとう@PrisonMike。 LinearLayoutを使用して私の問題を解決しました。私の答えを見てください。 –

答えて

0

2番目のレイアウトには制約がありません。 LinearLayoutが下部に揃えられ、リストビューがLinearLayoutの上にあることを確認する必要があります。

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

<ListView 
    android:id="@+id/message_list" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_above="@+id/llText" 
    android:divider="@null" /> 

<LinearLayout 
    android:id="@+id/llText" 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_alignParentBottom="true" 
    android:layout_height="wrap_content"> 

    <EditText 
     android:id="@+id/new_message" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="100" 
     android:inputType="text" 
     android:labelFor="@id/new_message" /> 

    <Button 
     android:id="@+id/send_message" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@color/colorPrimary" 
     android:text="Hello" 
     android:textColor="@android:color/white" /> 

</LinearLayout> 
</RelativeLayout> 
+0

ありがとう@Pavan。あなたの答えを試してみましょうが、私は私の答えに投稿するように線形レイアウトを使用して修正するように見えましたが、動作するかどうかを確認します。 –

+0

「LinearLayoutのレイアウトパラメータが無効です:layout_above」という2つのメッセージが表示されます。 : "廃止されました... LinearLayoutのレイアウトパラメータが正しくありません:layout_alignParentBottom –

+0

問題を解決できたらうれしいです。 これらのパラメータを線図レイアウトで使用しようとすると、上記のエラーが発生します。相対レイアウトが使用されているかどうかを確認してください。 私の解決策はエディタで動作するようですが、relativelayout終了タグがスニペットに表示されていませんでした。 ! – Pavan

0

これは何とか私の問題を解決しましたが、これまでにはうまくいきませんでした。

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    tools:context="com.example.app.MessageFragment"> 


    <ListView 
     android:id ="@+id/message_list" 
     android:layout_weight="100" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:divider="@null" 
     /> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <EditText 
      android:id="@+id/new_message" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="100" 
      android:inputType="text" 
      android:labelFor="@id/new_message" /> 

     <Button 
      android:id="@+id/send_message" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="@color/colorPrimary" 
      android:text="@string/send_message" 
      android:textColor="@android:color/white" /> 

    </LinearLayout> 

</LinearLayout> 
関連する問題