android – 将RelativeLayout分成两半

嗨我创建了一个包含2个按钮,一个单选按钮和一个图表视图的RelativeLayout.

我想现在在图表中显示两个不同的数据.

如何将RelativeLayout分成两半?

这是我目前的XML代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <Button
        android:id="@+id/BtnStart"
        android:layout_width="100dip"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginTop="5dip"
        android:text="SlaveEnable" />

    <Button
        android:id="@+id/BtnStop"
        android:layout_width="100dip"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginTop="5dip"
        android:layout_toRightOf="@id/BtnStart"
        android:text="SlaveDisable" />

    <RadioButton
        android:id="@+id/BtnSaveFile"
        android:layout_width="100dip"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_toRightOf="@id/BtnStop"
        android:text="SaveFile" />

    <helog.diwesh.NugaBest.GraphView
        android:id="@+id/gview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@id/BtnStart"
        android:layout_alignParentRight="true" />

</RelativeLayout>

解决方法

试试这个布局.如果不完美,这应该适用于一些变化.这将添加两个图表.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <Button
        android:id="@+id/BtnStart"
        android:layout_width="100dip"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginTop="5dip"
        android:text="SlaveEnable" />

    <Button
        android:id="@+id/BtnStop"
        android:layout_width="100dip"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginTop="5dip"
        android:layout_toRightOf="@id/BtnStart"
        android:text="SlaveDisable" />

    <RadioButton
        android:id="@+id/BtnSaveFile"
        android:layout_width="100dip"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_toRightOf="@id/BtnStop"
        android:text="SaveFile" />

<LinearLayout 
        android:layout_width="match_parent"
        android:layout_height="match_parent"
            android:layout_above="@id/BtnStart"
            android:layout_alignParentRight="true"
        android:orientation="vertical" 
    android:weightSum="2" >

    <helog.diwesh.NugaBest.GraphView
                android:id="@+id/gview1"
                android:layout_height="0dp"
                android:layout_width="match_parent"
        android:layout_weight="1" />

    <helog.diwesh.NugaBest.GraphView
                android:id="@+id/gview2"
                android:layout_height="0dp"
                android:layout_width="match_parent"
        android:layout_weight="1" />

</LinearLayout>

</RelativeLayout>

相关文章

ADB Remote ATV Android TV 的遥控器,基于 ADB Shell 命令 ...
使用Flutter自带的SearchDelegate组件实现搜索界面,通过魔改...
上篇文章讲解了怎么使用Kotlin的协程配合Retrofit发起网络请...
安卓开发——WebView+Recyclerview文章详情页,解决高度...
Android 如何解决dialog弹出时无法捕捉Activity的back事件 在...