xml - 如何设计微调器的这个 XML 文件
解决方案
试试这个代码:
首先创建一个可绘制文件
spinner_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<corners android:radius="5dp" />
<solid android:color="#F5F5F5"/>
<stroke android:width="3dp"
android:color="#454551"/>
</shape>
</item>
</selector>
现在,使用spinner_bg.xml
布局文件作为背景,布局文件的代码如下:
main_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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"
android:background="#F5F5F5"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/spinner_bg"
android:layout_marginTop="15dp">
<Spinner
android:id="@+id/spinner"
android:layout_width="match_parent"
android:layout_height="50dp"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Product Group"
android:textSize="18sp"
android:background="#F5F5F5"
android:layout_marginLeft="10dp"
android:padding="5dp"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/spinner_bg"
android:layout_marginTop="15dp">
<Spinner
android:id="@+id/spinner1"
android:layout_width="match_parent"
android:layout_height="50dp"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Literature"
android:textSize="18sp"
android:background="#F5F5F5"
android:layout_marginLeft="10dp"
android:padding="5dp"/>
</RelativeLayout>
</LinearLayout>
这是上述代码的输出:
我希望它对你有用。
推荐阅读
- python - 如何更改连接器形状连接到其他形状时的外观?
- angular - 在与 TemplateRef 相同的组件中访问 Angular ng-template
- java - 与面向对象的方法作斗争
- java - Spring注解方法用途
- c# - WindowInteropHelper.EnsureHandle() 的异常
- java - .properties 文件被覆盖。如何克服呢?
- javascript - 将base64转换为blob然后放回输入文件
- angular - 如何在 Angular 中使用 Stack Exchange API
- ios - 迁移到 Xcode 10.2
- python - 一袋句子