Android 可绘制资源文件只能在大屏幕上工作,不能在小屏幕上工作
我只想用下面的渐变填充屏幕的上半部分Android 可绘制资源文件只能在大屏幕上工作,不能在小屏幕上工作,android,android-studio,android-layout,Android,Android Studio,Android Layout,我只想用下面的渐变填充屏幕的上半部分 <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:bottom="500sp"> <shape android:shape="rectangle" > <corners
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:bottom="500sp">
<shape android:shape="rectangle" >
<corners
android:bottomLeftRadius="40sp"
android:bottomRightRadius="40sp" />
<gradient
android:startColor="#9CA0DD"
android:endColor="#ECB8B8"
android:angle="270" />
</shape>
</item>
</layer-list>
用于布局的xml
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/home_background_color">
</ScrollView>
这适用于大屏幕设备,但不适用于小屏幕,我使用“sp”而不是“dp”,但结果是一样的
请尝试另一种方法,因为无法在可绘制图形中指定百分比 您可以做的是在ScrollView后面放置一个视图,专门用于背景。并使用Constraintlayout作为主要选项,以获得更大的灵活性 因此,对于您的drawable,将与下一个一样(请注意,它必须全部在DPs中,而不是SPs中,并且您的“android:bottom=500sp”已完全删除):
对于主布局,必须与下一个相同(注意标记“app:layout\u constraintHeight\u percent=“0.5”):
作为旁注,仅对字体使用“sp”单位,而不对图形使用,对于任何非字体(文本大小)的内容,请始终使用“dp”单位。将记住这一点,谢谢。很有魅力
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<corners
android:bottomLeftRadius="40dp"
android:bottomRightRadius="40dp" />
<gradient
android:startColor="#9CA0DD"
android:endColor="#ECB8B8"
android:angle="270" />
</shape>
</item>
</layer-list>
<?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"
android:background="#FF303030"
tools:context=".MainActivity">
<View
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_percent="0.5"
android:background="@drawable/home_background_color" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.constraintlayout.widget.ConstraintLayout>