У меня возникают проблемы с выравниванием фрагментов с помощью RelativeLayout
, хотя кажется, что это должно быть просто. Мне просто нужно два фрагмента рядом друг с другом, и если я использую LinearLayout
он работает отлично:Выравнивание фрагментов с 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>
Однако, если я использую RelativeLayout
, ничего не показывает:
<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>
Обновление:
Вот скриншот того, что я вижу:
Это код, я использую:
<?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>
То, что я в конечном счете пытаюсь сделать, это добавить нижний колонтитул к нижней части макета, но я не мог заставить его работать с помощью 'LinearLayout'. Мне удалось отобразить нижний колонтитул с помощью «RelativeLayout», но тогда фрагменты не появлялись, поэтому я просто пытался получить фрагменты (без нижнего колонтитула), следовательно, мой вопрос. Похоже, мне нужно будет выяснить, как заставить нижний колонтитул работать с помощью «LinearLayout». Я в основном хочу макет, где левый фрагмент занимает 1/3 экрана, справа - остальная часть экрана, с липким нижним колонтитулом. –
Правильно, это не должно быть слишком сложно реализовать. См. Редактирование в моем ответе и дайте это. Не пробовал, но должен быть (близко к), что вам нужно. –
Это отлично поработало. Благодаря! –