分割屏幕分成两个相等的部分,不能设置layout_weight [英] Dividing screen into two equal parts , can not set layout_weight

查看:219
本文介绍了分割屏幕分成两个相等的部分,不能设置layout_weight的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想问题是愚蠢的,但我缺少这个东西,想明白。

I guess question is silly, but I am missing something in this and want to understand.

我分割屏幕分成两个相等的部分。我知道这可以通过设置权重来实现。但我不知道为什么我不能在线性布局设置权重。相反,我设置weightSum,但我明白那weightSum是,它在屏幕空间设置宽度和高度,我想后离开。

I am dividing the screen into two equal parts. I know this can be done by setting weight. But I do not know why I can not set weight in Linear layout. Instead I am setting weightSum, but what I understood about weightSum is, it is space on screen left after setting width and height I guess.

下面是我在做什么。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:background="#ffffff"
android:layout_height="match_parent"
android:id="@+id/main_panel">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/top"
android:weightSum="100">
   <ListView
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:id="@+id/list"
    android:divider="@null"
    android:dividerHeight="0dp"
    android:layout_marginTop="5dp"
    android:layout_marginBottom="5dp"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />
</LinearLayout>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@id/top"
    android:weightSum="50"
    android:layout_alignParentBottom="true"
    android:id="@+id/ bottom">
<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/data"
    android:orientation="vertical"
    android:background="#D3D3D3"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true">

    <View
        android:id="@+id/drag_line"
        android:layout_width="50dp"
        android:visibility="visible"
        android:background="@drawable/bar"
        android:layout_gravity="center_horizontal|top"
        android:layout_height="170dp"
        android:src="@drawable/line" />

</FrameLayout>
</LinearLayout>
</RelativeLayout>

PS:采用了android棒棒糖我无法设置layout_weight属性

PS: I cannot set layout_weight property using android lollipop

推荐答案

尝试低于code:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:background="#ffffff"
android:layout_height="match_parent"
android:id="@+id/main_panel">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:id="@+id/top"
>
   <ListView
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:id="@+id/list"
    android:divider="@null"
    android:dividerHeight="0dp"
    android:layout_marginTop="5dp"
    android:layout_marginBottom="5dp"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />
</LinearLayout>
<LinearLayout
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_below="@id/top"
    android:layout_weight="1"
    android:layout_alignParentBottom="true"
    android:id="@+id/ bottom">
<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/data"
    android:orientation="vertical"
    android:background="#D3D3D3"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true">

    <View
        android:id="@+id/drag_line"
        android:layout_width="50dp"
        android:visibility="visible"
        android:background="@drawable/bar"
        android:layout_gravity="center_horizontal|top"
        android:layout_height="170dp"
        android:src="@drawable/line" />

</FrameLayout>
</LinearLayout>
</RelativeLayout>

这篇关于分割屏幕分成两个相等的部分,不能设置layout_weight的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆