我在一个相对的布局中有一个框架布局,其他的东西都在它下面。如何使这个帧布局占据整个屏幕的一半?
我试过体重,但这改变不了什么。
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/mainLayoutStyle">
<FrameLayout
android:id="@+id/codeLayout"
style="@style/codeLayoutLargeStyle">
<TextView
android:id="@+id/DisplayTextView"
style="@style/DisplayTextViewLargeStyle"/>
</FrameLayout>
......
.....
<LinearLayout 发布于 2015-08-02 13:22:19
我在一个相对的布局中有一个框架布局,其他的东西都在它下面。
然后,您使用错误的布局作为您的父级。您应该将RelativeLayout替换为LinearLayout,将FrameLayout高度设置为match_parent和android:layout_weight="1",然后将所需的任何东西(相对的、线性的)包装到所需的以下,以确保它也得到了设置的高度和上面的layout_weight。然后你会得到50%-50%的高度分裂。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_weight="1"
android:background="#ff0000"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<RelativeLayout
android:layout_weight="1"
android:background="#0000ff"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>

发布于 2015-08-02 13:28:44
权重只适用于线性布局,而不是相对布局。
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/mainLayoutStyle"
android:weightSum="100">
<FrameLayout
android:id="@+id/codeLayout1"
style="@style/codeLayoutLargeStyle"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="50">
</FrameLayout>
<FrameLayout
android:id="@+id/codeLayout2"
style="@style/codeLayoutLargeStyle"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="50">
</FrameLayout>
</LinearLayout>给出每个布局高度0 0dp和重量50,并给出线性布局权重之和为100。
发布于 2015-08-02 13:39:32
Marcin是对的,只有当您将父布局作为线性布局,而要使框架布局覆盖半屏幕时,权重属性才会有效,您必须将两个布局作为该线性布局的子布局,并将其除以相等的权重。
e.g
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:id="@+id/you_frame_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#00ff00">
</FrameLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
</RelativeLayout>
希望这对你有帮助。
https://stackoverflow.com/questions/31772274
复制相似问题