1
A
回答
2
你必须使用Vector Drawable用于创建自定义形状,因为你需要。
我为此创建了一个样本。 创建custom_vector.xml下的文件RES /绘制/
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="20dp"
android:width="20dp"
android:viewportWidth="400"
android:viewportHeight="400">
<group
android:pivotX="10.0"
android:pivotY="10.0">
<!-- the outside box -->
<!-- top line & top left corner -->
<path android:pathData="M 30 60 H 40 c -40 0 -35 0 -35 35 "
android:strokeColor="#000000" android:strokeWidth="10" />
<!-- left line & bottom left corner -->
<path android:pathData="M 5 64 v 271 c 0 40 0 35 35 35 "
android:strokeColor="#000000" android:strokeWidth="10" />
<!-- bottom line & bottom right corner -->
<path android:pathData="M 30 370 h 330 c 40 0 35 -10 35 -35"
android:strokeColor="#000000" android:strokeWidth="10" />
<!-- right line & top right corner -->
<path android:pathData="M 395 356 v -261 c0 -40 0 -35 -50 -35"
android:strokeColor="#000000" android:strokeWidth="10" />
<!-- top line till end-->
<!-- 140 is the starting point of line after TEXT-->
<path android:pathData="M 140 60 370 60"
android:strokeColor="#000000" android:strokeWidth="10" />
</group>
</vector>
您可能需要更改的最后一个路径变量的值
顶线,直到结束
为根据您的文本在处'姓名'。您也可以根据需要修改形状或角落。
下RES /布局创建test_layout.xml文件/
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#faffd5">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/custom_vector"
android:layout_margin="20dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:paddingLeft="5dp"
android:textSize="20sp"
android:paddingRight="5dp"
android:text="Name"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="15dp"
android:textSize="25sp"
android:background="@android:color/transparent"
android:text="Alex Smith"/>
</LinearLayout>
</LinearLayout>
看起来像这样的屏幕截图
1
试试下面...
你实现这个使用ConstraintLayout
。
<?xml version="1.0" encoding="utf-8"?>
<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/linearLayout"
android:layout_width="match_parent"
android:background="@android:color/white"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:id="@+id/edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/_10sdp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:background="@drawable/round"
android:padding="@dimen/_10sdp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:padding="@dimen/_5sdp"
android:text="Name"
app:layout_constraintLeft_toLeftOf="@+id/edittext"
android:layout_marginLeft="@dimen/_15sdp"
app:layout_constraintTop_toTopOf="@+id/edittext"
app:layout_constraintBottom_toTopOf="@+id/edittext"
android:textColor="@android:color/black"
tools:layout_editor_absoluteX="107dp"
tools:layout_editor_absoluteY="90dp" />
</android.support.constraint.ConstraintLayout>
round.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- res/drawable/rounded_edittext.xml -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">
<solid android:color="#FFFFFF"/>
<stroke android:color="@android:color/darker_gray" android:width="@dimen/_1sdp"/>
<corners
android:bottomRightRadius="15dp"
android:bottomLeftRadius="15dp"
android:topLeftRadius="15dp"
android:topRightRadius="15dp"/>
</shape>
输出:see
+0
谢谢,但我有背景图像在屏幕周围,所以我想让ui透明,以便背景图像不会影响 – Aditi
+0
明白了你的观点......如果我找到了你想要的东西,我会更新你。 –
相关问题
- 1. 使六边形形状的边框,圆角和透明背景
- 2. 背景上的圆角?
- 3. 图像角落上的圆角边界渐变背景拉伸
- 4. Delphi TRichEdit将背景形状设置为圆角矩形
- 5. CSS圆角表角落,渐变背景
- 6. Firefox中的圆角:边框和背景之间的空间
- 7. CSS - 左上角背景图像(弯曲)
- 8. android:带有动态背景颜色的圆角背景的TextView
- 9. 添加背景圆角[CSS/Twitter的Bootstrap]
- 10. 边框背景上的Style.DataTrigger
- 11. NSAttributedString背景颜色和圆角
- 12. UIImageView圆角有白色背景
- 13. WPF圆角背景出血通过
- 14. 圆角IE和背景图像
- 15. IE9圆角和透明背景问题
- 16. 如何创建背景CSS div /圆角?
- 17. 没有边框的圆角矩形UIButton
- 18. 删除圆角面包屑的左右背景颜色
- 19. 如何创建矩形背景的六角形?
- 20. 用css背景和圆角边界的Firefox溢出错误
- 21. 的iOS设置中的UILabel文本背景色(用圆角矩形)
- 22. AwesomeWM提示框背景
- 23. Android:不改变背景颜色的圆形按钮角落
- 24. 输入元素上的圆形背景
- 25. StateHighlighted上更改圆形矩形按钮背景色
- 26. 六角形图像背景css
- 27. 交替三角形彩色背景
- 28. 为UITableViewCells(分组样式)使用背景图像 - 角不圆形
- 29. 矩形背景色RichTextBox中
- 30. Android矩形背景渐变
创建一个由的EditText和TextView的和然后的相对布局使用您的可绘制背景进行特定布局,并添加文本和编辑文本提示 – YoLo
@ysl我想背景透明nt,因为我在屏幕上有背景图像。 – Aditi
然后不要设置背景颜色为您的可绘制 – YoLo