【发布时间】:2019-11-16 09:21:25
【问题描述】:
我正在尝试在 CardView 内移动 ImageView。我有一个带有一些文本和一个 ImageView 的 CardView,我想将我的圆形 ImageView 放在中心的文本上方。
在图片中你可以看到 CardView 左上角的绿色可绘制圆圈,并且 TextView 居中。 ImageView stuck at top left of CardView
这是我当前的代码:
<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:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".HomePageActivity"
style="@android:style/TextAppearance.DeviceDefault.Medium">
...在我拥有的 ConstraintLayout 内部:
<android.support.v7.widget.CardView
android:id="@+id/create_invoice_cardview"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="@dimen/button_gap_normal"
android:layout_marginTop="185dp"
android:layout_marginEnd="@dimen/margin_width_normal"
android:layout_marginBottom="@dimen/button_gap_normal"
app:layout_constraintBottom_toTopOf="@+id/add_single_cardview"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/capture_receipt_cardview"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/inset_background"
android:padding="10dp"
android:src="@drawable/ic_photo_camera_black_24dp" />
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:paddingTop="25dp"
android:text="Create Invoice"
android:autoSizeTextType="uniform"
android:autoSizeMaxTextSize="25sp"
/>
</android.support.v7.widget.CardView>
我曾尝试在 inset_background 可绘制对象中使用 inset,但它只是将圆形挤压成椭圆形而不移动它。
如何在 CardView 内移动 ImageView,同时保持可绘制形状为圆形?
我希望此解决方案在我修改手机屏幕大小时相应地调整大小。即我不想要一个在 Pixel XL 上小而在 Nexus 4 上大的硬编码尺寸。
为了更好地了解我在寻找什么,this is what I am trying to design
【问题讨论】:
标签: android android-studio imageview cardview