Aya*_*dro 18 android border android-relativelayout
我已经看过这个 关于在android textview周围设置边框的主题,并且我使用了它.但现在,我想在小部件周围放置边框,这些小部件位于相对布局中.我该怎么做?
RWI*_*WIL 46
res/drawable文件夹中,创建一个新文件background_border.xml在此文件中,您将为此窗口小部件定义背景:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<!-- This is the stroke you want to define -->
<stroke android:width="1dp"
android:color="@color/color_stroke"/>
<!-- Optional, round your corners -->
<corners android:bottomLeftRadius="0dp"
android:topLeftRadius="5dp"
android:bottomRightRadius="5dp"
android:topRightRadius="0dp" />
<!-- Optional, fill the rest of your background with a color or gradient, use transparent if you only want the border to be displayed-->
<gradient android:startColor="@android:color/transparent"
android:endColor="@android:color/transparent"
android:angle="90"/>
</shape>
Run Code Online (Sandbox Code Playgroud)
例如.如果你想把你的边框放在relativelayout上:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/background_border"
android:padding="15dp">
...
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
小智 11
RelativeLayout layout = (RelativeLayout) view.findViewById(R.id.borderEffect); // id fetch from xml
ShapeDrawable rectShapeDrawable = new ShapeDrawable(); // pre defined class
// get paint
Paint paint = rectShapeDrawable.getPaint();
// set border color, stroke and stroke width
paint.setColor(Color.GRAY);
paint.setStyle(Style.STROKE);
paint.setStrokeWidth(5); // you can change the value of 5
layout.setBackgroundDrawable(rectShapeDrawable);
Run Code Online (Sandbox Code Playgroud)
创建一个获取边框的背景颜色以及边框宽度的边距或填充的 FrameLayout,并将该 FrameLayout 放置在您的relativelayout 中。将 TextView 放置在 FrameLayout 中,而不是直接放置在relativelayout 中。噗即时边框。
| 归档时间: |
|
| 查看次数: |
30012 次 |
| 最近记录: |