android - 如何为线性布局赋予圆角?
问题描述
我想LinearLayout
用圆角覆盖我的顶部,ImageView
但背景中仍然有白色。如何删除它?
活动主
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ImageView
android:id="@+id/imageView"
android:layout_width="0dp"
android:layout_height="0dp"
android:contentDescription="@string/todo"
android:scaleType="centerCrop"
app:layout_constraintBottom_toTopOf="@+id/linearLayout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/mountains" />
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@drawable/linear_layout"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-condensed-medium"
android:padding="15dp"
android:text="@string/the_white_mountains"
android:textAllCaps="true"
android:textColor="@color/black"
android:textSize="20sp" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
线性布局
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/black"/>
<corners android:topLeftRadius="15dp" android:topRightRadius="15dp"/>
</shape>
我如何去除那些白色的角落?
解决方案
你的drawable很好,但你需要调整约束,因为ImageView
它不会占据屏幕的整个高度,因此它不会与LinearLayout
.
因此,将ImageView
底部约束添加到父级而不是顶部LinearLayout
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ImageView
android:id="@+id/imageView"
android:layout_width="0dp"
android:layout_height="0dp"
android:contentDescription="@string/todo"
android:scaleType="centerCrop"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/mountains" />
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@drawable/linear_layout"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-condensed-medium"
android:padding="15dp"
android:text="@string/the_white_mountains"
android:textAllCaps="true"
android:textColor="@color/black"
android:textSize="20sp" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
预习
推荐阅读
- sql-server - 无法从其他计算机连接到本地 SQL Server 数据库
- python - 无法使用散景图的“desired_num_ticks”。抛出的错误是“‘NoneType’对象没有属性‘desired_num_ticks’”
- go - indexof 的等价物
- flutter - 请为flutter中的插件设置什么约束?
- javascript - 使用 vue-custom-element 和 Vuex 时,子组件中 this.$store 的值未定义
- python - 使用 pandas 统计从开始时间起一小时内发生的用户订单,时间间隔不规则
- apache-kafka - Kafka - 如何知道它是代理属性还是主题属性还是生产者属性
- node.js - Sequelize中的内部联接查询引用多个表
- css - Bootstrap 卡片组无法对齐卡片高度
- visual-studio - 无法从解决方案资源管理器中将 LINQ 添加到 SQL 类