Mam prawdziwe problemy z dopasowaniem fragmentów do RelativeLayout
, chociaż wydaje się, że powinno to być proste. Muszę tylko dwa fragmenty obok siebie i jeśli mogę użyć LinearLayout
to działa dobrze:Wyrównanie fragmentów za pomocą 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>
Jednakże, jeśli mogę użyć RelativeLayout
, nic nie pokazuje:
<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>
Aktualizacja:
Oto zrzut ekranu z tego, co widzę:
Jest to kod używam:
<?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>
Ostatecznie próbuję dodać stopkę do dolnej części układu, ale nie mogłem jej uruchomić za pomocą 'LinearLayout'. Udało mi się pokazać stopkę za pomocą "RelativeLayout", ale fragmenty się nie pojawiły, więc próbowałem tylko pokazać fragmenty (bez stopki), stąd moje pytanie. Wygląda na to, że muszę wymyślić, jak uruchomić stopkę za pomocą 'LinearLayout'. Zasadniczo chcę układu, w którym lewy fragment zajmuje 1/3 ekranu, a prawa reszta ekranu, z lepką stopką. –
Dobrze, nie powinno to być zbyt trudne do zrealizowania. Zobacz edycję w mojej odpowiedzi i daj z siebie wszystko. Nie próbowałem tego, ale powinno być (blisko) tego, czego szukasz. –
To działało świetnie. Dzięki! –