Pep*_*llo 7 shadow android-elevation android-constraintlayout
如何在使用阴影的视图中显示高程ConstraintLayout?
使用Relative和Linear可以执行带阴影的高程来实现列表,但我不能这样做ConstraintLayout.
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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="wrap_content"
android:background="#fff"
android:orientation="vertical">
<TextView
android:id="@+id/list_ssid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:elevation="8dp"
android:background="#fff"
android:text="SSID"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/guideline"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/list_ch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:elevation="8dp"
android:background="#fff"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="CH"
app:layout_constraintLeft_toLeftOf="@+id/guideline"
app:layout_constraintRight_toLeftOf="@+id/guideline2"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/list_dB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:elevation="8dp"
android:background="#fff"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="dB"
app:layout_constraintLeft_toLeftOf="@+id/guideline2"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.constraint.Guideline
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.65"
tools:layout_editor_absoluteX="239dp"
tools:layout_editor_absoluteY="0dp" />
<android.support.constraint.Guideline
android:id="@+id/guideline2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.83"
tools:layout_editor_absoluteX="306dp"
tools:layout_editor_absoluteY="0dp" />
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
Nuz*_*zha 11
出于某种原因,ConstraintLayout如果你给出一个虚拟drawable作为背景,那么提升会起作用::
创建一个drawable:
dummyBg.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="@android:color/white"/>
<corners android:radius="2dp" />
</shape>
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)
使用此作为视图的背景并像往常一样使用高程.
android:elevation="8dp"
android:background="@drawable/dummyBg"
android:padding="4dp"
Run Code Online (Sandbox Code Playgroud)
所以你会得到:
<TextView
android:id="@+id/list_ssid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="6dp"
android:layout_marginBottom="2dp"
android:elevation="8dp"
android:background="@drawable/dummyBg"
android:padding="4dp"
android:text="SSID"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/guideline"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
Run Code Online (Sandbox Code Playgroud)
Leo*_*der 10
为了使高程工作,您只需为视图设置背景颜色。
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/your_color"
android:text="SSID"/>
Run Code Online (Sandbox Code Playgroud)
它是什么类型的 View 无关紧要,是
ConstraintLayout 或 ConstraintLayout 本身的孩子
您也可以使用十六进制颜色或颜色属性。
请注意,它不能完全透明。
| 归档时间: |
|
| 查看次数: |
5829 次 |
| 最近记录: |