【发布时间】:2016-11-02 15:36:22
【问题描述】:
我有这个问题。我想把这个布局放在这张图片上:
图片尺寸为 297x199。在 android 上,我想在这个图像中放一个黑色的 EditText,如下所示:
并且无法在此处添加正确大小的 EditText。
我项目的xml是:
<RelativeLayout 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:background="EBEBF1"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="230dp"
android:layout_marginTop="9dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginLeft="9dp"
android:layout_marginRight="9dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="@string/cas"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="39dp"
android:layout_marginStart="39dp"
android:id="@+id/textView2"
android:textStyle="normal|bold"
android:textSize="18sp"
android:textColor="#000"
android:layout_marginBottom="16dp"
android:layout_alignBottom="@+id/imageView11"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ImageView
android:layout_width="250dp"
app:srcCompat="@drawable/photoframe"
android:id="@+id/imageView11"
android:layout_marginTop="49dp"
android:layout_height="90dp"
android:layout_alignParentTop="true"
android:layout_alignLeft="@+id/textView2"
android:layout_alignStart="@+id/textView2"
android:layout_marginLeft="22dp"
android:layout_marginStart="22dp" />
<EditText
android:layout_height="35dp"
android:inputType="numberSigned"
android:ems="10"
android:background="#000"
android:id="@+id/editText2"
android:layout_width="65dp"
android:layout_marginLeft="46dp"
android:layout_alignBottom="@+id/textView2"
android:layout_toRightOf="@+id/textView2"
android:layout_marginStart="46dp" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
有没有办法做到这一点?此图片的尺寸是否正确?
【问题讨论】:
-
您不能将任何东西放入 ImageView。你可以撅撅撅 到它。但是您可以将图像作为 View 的背景。包括一个 EditText。对于“正确的大小”,我会改用 9 补丁。
-
唯一的方法是使用 Photoshop 等调整图像大小?
-
为什么不使用 9 补丁?
-
@Rotwang 9 补丁是如何工作的?