【问题标题】:FrameLayout inside the FrameLayout and positioning FrameLayout right side of the parent FrameLayout?FrameLayout里面的FrameLayout和定位FrameLayout右边的父FrameLayout?
【发布时间】:2012-12-10 13:54:12
【问题描述】:

我正在尝试创建一个包含子 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>

截图:

如上图所述,我想将白色的 FrameLayout 向右移动。

谢谢

【问题讨论】:

    标签: android android-layout android-framelayout


    【解决方案1】:

    来自Android DocumentationFrameLayout

    FrameLayout 的设计目的是在屏幕上屏蔽一个区域以显示 单个项目

    您应该使用LinearLayout 或RelativeLayout 作为root,除非您想在任何给定时间只显示一个孩子。我假设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 !
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-17
    • 1970-01-01
    • 1970-01-01
    • 2018-01-30
    • 1970-01-01
    相关资源
    最近更新 更多