Ich habe echte Probleme beim Ausrichten von Fragmenten mit einer RelativeLayout
, obwohl es scheint, sollte dies einfach sein. Ich brauche nur zwei Fragmente nebeneinander, und wenn ich eine LinearLayout
verwenden, es funktioniert:Ausrichten von Fragmenten mit RelativeLayout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<fragment android:name="com.fragment.test.TitlesFragment"
android:id="@+id/fragmentTitles"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="fill_parent"
/>
<FrameLayout
android:id="@+id/details"
android:layout_weight="1"
android:layout_width="0px"
android:layout_height="fill_parent"
/>
</LinearLayout>
Wenn ich jedoch eine RelativeLayout
verwenden, nichts zeigt:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<fragment android:name="com.fragment.test.TitlesFragment"
android:id="@+id/fragmentTitles"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="fill_parent"
/>
<FrameLayout
android:id="@+id/details"
android:layout_weight="1"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_toRightOf="@id/fragmentTitles"
/>
</RelativeLayout>
Aktualisierung:
Hier ist ein Screenshot von dem, was ich sehe:
Dies ist der Code Ich verwende:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:orientation="horizontal"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:weightSum="3"
>
<fragment android:name="com.fragment1"
android:id="@+id/fragment1"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_above="@id/statusUpdated"
/>
<fragment android:name="com.fragment2"
android:id="@+id/fragment2"
android:layout_width="0px"
android:layout_weight="2"
android:layout_height="fill_parent"
android:layout_above="@id/statusUpdated"
android:layout_toRightOf="@id/fragment1"
/>
</LinearLayout>
<TextView android:id="@+id/statusUpdated" style="@style/Status" />
</RelativeLayout>
Was ich letztendlich versuche zu tun ist eine Fußzeile am unteren Rand des Layouts hinzuzufügen, aber ich konnte es nicht mit einem 'LinearLayout' arbeiten. Ich konnte die Fußzeile mit einem 'RelativeLayout' zeigen, aber dann erschienen die Fragmente nicht, also versuchte ich nur die Fragmente zu bekommen (ohne Fußzeile), daher meine Frage. Klingt so, als müsste ich herausfinden, wie man die Fußzeile mit einem 'LinearLayout' zur Arbeit bringt. Ich möchte grundsätzlich ein Layout, bei dem das linke Fragment 1/3 des Bildschirms einnimmt, das rechte den Rest des Bildschirms, mit einer klebrigen Fußzeile. –
Richtig, das sollte nicht zu schwer zu realisieren sein. Bitte beachten Sie die Bearbeitung in meiner Antwort und geben Sie es an. Habe es nicht ausprobiert, aber es sollte (nahe) sein, wonach du suchst. –
Das hat super funktioniert. Vielen Dank! –