私は、リストビュー、編集テキストボックス、チュートリアルのオンラインで見つかったボタンからなるメッセージインターフェースを持っています。 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>
を私の問題は解決していません。
2番目のレイアウトに複数の問題があります。あなたはandroid:orientation = "vertical"をrelativelayoutで使うことはできません。 – PrisonMike
ありがとう@PrisonMike。 LinearLayoutを使用して私の問題を解決しました。私の答えを見てください。 –