FrameLayout内嵌于FrameLayout中,并将FrameLayout定位在父FrameLayout的右侧?

3
我试图创建一个包含子Framelayout的Framelayout,但是我无法将子Framelayout定位到父Framelayout的右侧。
我尝试使用android:foregroundGravity="right"和android:layout_weight="1"。
 <?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/listView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" 
    android:layout_weight="1">    

<com.example.ListViewActivity
        android:id="@+id/list_view"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
</com.example.ListViewActivity>

    <FrameLayout
        android:id="@+id/indexRight"
        android:layout_width="36dp"
        android:layout_height="fill_parent"
        android:layout_gravity="left"
        android:background="@color/white"      
        android:orientation="vertical" >

    </FrameLayout>

</FrameLayout>

屏幕截图:enter image description here

如上图所示,我想将白色的FrameLayout移动到右侧。

谢谢。

1个回答

1

来自Android文档关于FrameLayout

FrameLayout旨在阻挡屏幕上的某个区域以显示单个项目。

除非您只想在任何给定时间仅显示一个子项,否则应将LinearLayoutRelativeLayout用作根。我假设com.example.ListViewActivity是您实现的自定义视图,而不是实际的Activity

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/listView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal">    

    <com.example.ListViewActivity
        android:id="@+id/list_view"
        android:layout_width="0dp"
        android:layout_height="fill_parent" 
        android:layout_weight="1">
    </com.example.ListViewActivity>

    <!-- This FrameLayout will be located on the right side, with the ListView on its left side -->
    <FrameLayout
        android:id="@+id/indexRight"
        android:layout_width="36dp"
        android:layout_height="fill_parent"
        android:background="@color/white">
        <!-- SINGLE child here -->
    </FrameLayout>
</LinearLayout>

谢谢,'com.example.ListViewActivity'自定义视图应包含父FrameLayout! - LOG_TAG

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接