【发布时间】:2017-10-22 11:29:52
【问题描述】:
我有一点Android 开发者的问题。如第二张图片所示,我希望在 EditText 附近有一个圆形(完美圆形)按钮。为了实现这一点,我使用了一个单独的布局(第一张图片),我在其中定义了带有形状的按钮(如下所示)。由于我想有一个完美的圆圈,我把这个布局放在一个约束布局中,以保持比例。 现在,既然这种方式行不通:我怎样才能实现一个完美的圆圈? 考虑到这一点,我不能放入形状布局,因为此按钮的尺寸可能会因不同的活动而变化。
这是形状文件,用 android:shape="oval" 设置(环不能正常工作):
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid
android:color="#666666"/>
这是按钮布局:
<?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:id="@+id/ll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<Button
android:id="@+id/circle_button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="dadada"
android:background="@drawable/ring_shape" />
</LinearLayout>
这是使用按钮的布局。考虑到这是一个 recyclerView 的单行:
<?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:id="@+id/category_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:orientation="horizontal"
android:weightSum="6">
<android.support.constraint.ConstraintLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<include
layout="@layout/circle_button_layout"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintDimensionRatio="h,1:1" />
</android.support.constraint.ConstraintLayout>
<EditText
android:id="@+id/category_name_row"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:inputType="textAutoCorrect"
android:background="@android:color/transparent"
android:layout_weight="3.4"
android:textColor="@color/category_text"
android:textSize="@dimen/payment_text"/>
<ImageButton
android:id="@+id/category_btn_confirm_change"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:src="@drawable/ic_btn_done"
android:tint="@color/hint_text"
android:layout_gravity="center_vertical"
android:background="@color/transparent"
android:layout_marginRight="15dp"
android:layout_marginEnd="15dp"
android:layout_weight="0.8"/>
<ImageButton
android:id="@+id/category_btn_delete"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:src="@drawable/ic_btn_delete"
android:tint="@color/hint_text"
android:layout_gravity="center_vertical"
android:background="@color/transparent"
android:layout_marginRight="15dp"
android:layout_marginEnd="15dp"
android:layout_weight="0.8"/>
</LinearLayout>
一些图片只是为了清楚:
【问题讨论】:
标签: android xml android-layout button shape