【发布时间】:2018-06-24 20:52:54
【问题描述】:
我需要使用 Spinner 和带有背景轮廓的 center 文本。
但是当我申请Button时,它工作正常。但是当我用Spinner替换时也是一样,下拉不可见,文本不在中心。
下面的Button 可以很好地与背景可绘制border_grey_curve 配合使用。
<!-- <android.support.v7.widget.AppCompatButton
android:id="@+id/to_day"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.5"
android:background="@drawable/border_grey_curve"
android:drawableRight="@drawable/dropdown"
android:gravity="center"
android:paddingRight="10dp"
android:text="Kamis"
android:textAllCaps="false" />-->
但如果我在Spinner 中应用相同的内容,则下拉菜单不会出现。而且文本也没有居中。
这里是微调器:
<android.support.v7.widget.AppCompatSpinner
android:id="@+id/to_day"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.5"
android:background="@drawable/border_grey_curve"
android:drawableRight="@drawable/dropdown" //applied drop down icon which is not displaying.
android:gravity="center" //not displaying text to center in spinner.
android:paddingRight="10dp"
android:text=""
android:textAllCaps="false" />
border_grey_curve.xml:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#ffffff"/>
<corners android:radius="5dp" />
<stroke
android:width="1dp"
android:color="#d2d2d2"
/>
</shape>
</item>
</selector>
更新了完整的 xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="5dp"
android:weightSum="5.3">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="2">
<com.customviews.CircleImageView
android:id="@+id/recycle_profile"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center"
android:layout_marginLeft="8dp"
android:src="@drawable/ic_default_profile" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:orientation="vertical"
android:paddingLeft="3dp">
<TextView
android:id="@+id/recycle_txt_acc_num"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1.25"
android:gravity="center_vertical"
android:text="12345678"
android:textColor="@color/colorBlack"
android:textSize="12sp" />
<TextView
android:id="@+id/recycle_txt_acc_name"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1.5"
android:text="SE A"
android:textColor="?attr/colorUserGroup"
android:textSize="12sp" />
</LinearLayout>
</LinearLayout>
<android.support.v7.widget.AppCompatButton
android:id="@+id/from_day"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.7"
android:background="@drawable/border_grey_curve"
android:gravity="center"
android:text=""
android:textAllCaps="false"
android:textColor="@color/colorBlack"
android:textSize="12sp" />
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_weight=".10"
android:background="@drawable/right_arrow"
android:gravity="center" />
<!-- <android.support.v7.widget.AppCompatButton
android:id="@+id/to_day"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.5"
android:background="@drawable/border_grey_curve"
android:drawableRight="@drawable/dropdown"
android:gravity="center"
android:paddingRight="10dp"
android:text="Kamis"
android:textAllCaps="false" />-->
<android.support.v7.widget.AppCompatSpinner
android:id="@+id/to_day"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.5"
android:background="@drawable/border_grey_curve"
android:drawableRight="@drawable/dropdown"
android:gravity="center"
android:paddingRight="10dp"
android:text=""
android:textAllCaps="false" />
</LinearLayout>
</RelativeLayout>
【问题讨论】:
标签: android android-layout android-spinner android-drawable android-button