Android 在另一个框架布局中插入框架布局
我可以在一个frameLayout中插入两个frameLayout吗? 我试过这个代码,但它不起作用Android 在另一个框架布局中插入框架布局,android,android-layout,Android,Android Layout,我可以在一个frameLayout中插入两个frameLayout吗? 我试过这个代码,但它不起作用 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:baselineAligned="false" an
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:orientation="horizontal" >
<FrameLayout
android:id="@+id/titles"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="1" />
<FrameLayout
android:id="@+id/details"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="2" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:baselineAligned="false"
android:orientation="horizontal" >
<FrameLayout
android:id="@+id/details1"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="1" />
<FrameLayout
android:id="@+id/details2"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="1" />
</LinearLayout>
</FrameLayout>
</LinearLayout>
当我单击一个元素时,我希望打印detail1。我猜detail1是在details下创建的,所以我看不到它
有人能帮忙吗
这就是我想要的:
如果所有的宽度都是0px,那么你会看到什么?不要用px,用dip。不管怎样,我不知道你想达到什么目的
[删除我的答案]我认为问题在于你没有完全理解如何使用布局权重。您必须更好地跟踪哪些视图族(父视图和子视图)连接到设计中的不同布局权重 我不完全确定应该如何工作,但我假设您希望左侧菜单始终可见,然后根据用户的选择动态显示更多详细信息。您还希望地图始终部分可见吗 我们已经收集了一些代码来实现上述功能。玩转这些代码,您可能会理解它是如何工作的。如果您在理解代码方面有问题,或者我误解了您的需求,请告诉我 main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1.0"
android:orientation="vertical"
android:background="@android:color/white"
>
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Menu"
android:textColor="@android:color/black"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Show Details"
android:onClick="showdetails" />
</LinearLayout>
<FrameLayout
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="2.0"
>
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/ic_launcher" />
<LinearLayout
android:id="@+id/DetailsLinearLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="gone"
>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1.0"
android:text="Details"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/black"
android:background="@android:color/white" />
<!-- This view is only here to prevent textView2 from completly
covering the underlying picture -->
<View
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1.0" />
</LinearLayout>
</FrameLayout>
</LinearLayout>
答案如下:
<?xml version="1.0" encoding="utf-8"?>
<!--
Top-level content view for the layout fragment sample. This version is
for display when in landscape: we can fit both titles and dialog.
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:baselineAligned="false"
android:orientation="horizontal" >
<FrameLayout
android:id="@+id/titles"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="1" />
<FrameLayout
android:id="@+id/details"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="2" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:baselineAligned="false"
android:orientation="horizontal" >
<FrameLayout
android:id="@+id/titles1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" />
<FrameLayout
android:id="@+id/details1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" />
<FrameLayout
android:id="@+id/details2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" />
</LinearLayout>
</RelativeLayout>
我得到了好结果:)
感谢大家的帮助,谢谢这不行:android:layout\u width=“match\u parent”在所有屏幕上制作我的框架布局,android:layout\u weight=“2”行不通。为什么不画一些草图并发布到这里,让我们看看你想要什么。我已经加入到我的问题的图片中了哈!千言万语的图画!我不知道你想为平板电脑这么做。如果是这样的话,我想您应该做类似的事情,我不认为一个xml布局就可以了。在这里试试这个源代码是的,它会像这样,但是没有onScrollview,只有onClick,所以我会使用片段
<?xml version="1.0" encoding="utf-8"?>
<!--
Top-level content view for the layout fragment sample. This version is
for display when in landscape: we can fit both titles and dialog.
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:baselineAligned="false"
android:orientation="horizontal" >
<FrameLayout
android:id="@+id/titles"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="1" />
<FrameLayout
android:id="@+id/details"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="2" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:baselineAligned="false"
android:orientation="horizontal" >
<FrameLayout
android:id="@+id/titles1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" />
<FrameLayout
android:id="@+id/details1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" />
<FrameLayout
android:id="@+id/details2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" />
</LinearLayout>
</RelativeLayout>