android - 如何在嵌套视图中水平划分视图
问题描述
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray"/>
我已经尝试了上面的代码,但没有做任何事情也尝试将高度更改为其他值,并且当使用上面的代码预览停止显示时,是否有一个好的小部件。我真的不想使用图像,因为很难将其他组件与之匹配。我也希望它相对定位。谢谢 这是下面代码的预览图片 https://i.stack.imgur.com/GD7Ro.png
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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">
<LinearLayout
android:baselineAligned="false"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="12dp"
android:layout_marginTop="12dp"
android:text="Team A"
android:textSize="24sp" />
<TextView
android:id="@+id/points"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="12dp"
android:text="0"
android:textSize="24sp" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:onClick="on3p"
android:text="+3 Points" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginTop="12dp"
android:onClick="on2p"
android:text="+2 Points" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="12dp"
android:onClick="on1p"
android:text="Free Throw" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="12dp"
android:layout_marginTop="12dp"
android:text="Team B"
android:textSize="24sp" />
<TextView
android:id="@+id/points2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="12dp"
android:text="0"
android:textSize="24sp" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:onClick="on3pb"
android:text="+3 Points" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="12dp"
android:onClick="on2pb"
android:text="+2 Points" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="12dp"
android:onClick="on1pb"
android:text="Free Throw" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:text="Reset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginLeft="150dp"
android:layout_marginBottom="20dp"
android:onClick="rst"/>
</LinearLayout>
</RelativeLayout>
解决方案
<RelativeLayout>
<linearLayout>
<LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray"/>
<LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
推荐阅读
- typo3 - 调度程序任务出现 TYPO3 错误 - “任务未能成功执行”
- android - LiveData.value 返回 Null 但 Livedata 直接观察它得到结果
- r - 如何在R中的数据帧的一行中找到两个最高值和两个最低值
- graphics - android 12 移植:Surfaceflinger 死锁
- reactjs - 如何在自定义插件中实现共享十字准线 - Grafana
- pandas - 概率变异数据框
- php - 在 Laravel 中检索列值数组的更好方法?
- php - PHP:在类中调用具有返回值的函数
- python - 在 spacy 训练数据中基于 NER 实体标签过滤数据
- c++ - 如何获取有关代码包含的文件、类和函数的信息?