【发布时间】:2018-03-22 14:25:34
【问题描述】:
我需要在 Android 上围绕 ImageView 设置一个矩形边框。
我不知道图像的确切比例,所以将高度和宽度设置为wrap_content。 ImageView 受限于顶视图和底视图。
如何在图像周围精确地绘制边框?没有完整的 ImageView?
我的 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"
android:background="@color/outer_background"
android:orientation="vertical">
<include layout="@layout/toolbar"/>
<RelativeLayout
android:id="@+id/login_layout_container"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="16dp"
android:layout_weight="1">
<ImageView
android:id="@+id/login_course_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/login_layout_account_fields"
android:layout_alignParentTop="true"
android:background="@drawable/border_course_logo"
tools:ignore="contentDescription"/>
<ProgressBar
android:id="@+id/login_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:indeterminate="true"
android:visibility="gone"/>
<RelativeLayout
android:id="@id/login_layout_account_fields"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="top"
tools:ignore="textFields">
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
border_course_logo.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@android:color/transparent"/>
<stroke
android:width="1dp"
android:color="@color/divider"/>
<padding
android:bottom="1dp"
android:left="1dp"
android:right="1dp"
android:top="1dp"/>
</shape>
【问题讨论】:
标签: android android-layout android-imageview