Kri*_*s B 7 android relativelayout android-layout android-linearlayout android-fragments
我试图将片段与a对齐时遇到了实际问题RelativeLayout,尽管看起来这应该是直截了当的.我只需要彼此相邻的两个片段,如果我使用LinearLayout它可以正常工作:
<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>
Run Code Online (Sandbox Code Playgroud)

但是,如果我使用a 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>
Run Code Online (Sandbox Code Playgroud)

更新:
这是我所看到的截图:

这是我正在使用的代码:
<?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>
Run Code Online (Sandbox Code Playgroud)
你不能使用权重RelativeLayout.基本上,该属性会被忽略,这意味着您的片段的宽度都会呈现0,因此它们不可见.
我不确定你要完成什么,但你可能想考虑将你的第一个例子(the LinearLayout)包装成一个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:id="@+id/fragment_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/footer_view"
android:weightSum="3">
<fragment
android:id="@+id/fragmentTitles"
android:name="com.fragment.test.TitlesFragment"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1" />
<FrameLayout
android:id="@+id/details"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="2" />
</LinearLayout>
<TextView
android:id="@+id/footer_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#f00"
android:text="I am a footer" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
显然你可以用TextView你喜欢的任何东西替换它.
| 归档时间: |
|
| 查看次数: |
13653 次 |
| 最近记录: |