Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
204 views
in Technique[技术] by (71.8m points)

android - How I can create rounded layout with two vertical line?

I want to put two vertical lines in a rounded layout (linear or relative)

Like this picture:

layout with rounded corners, contains two vertical lines

EDIT:

My try:

<RelativeLayout
    android:background="@drawable/rounded_bg"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <View
        android:layout_width="5dp"
        android:layout_height="match_parent"
        android:layout_alignParentRight="true"
        android:layout_marginRight="10dp"
        android:background="@color/colorPrimaryDark" />


</RelativeLayout>

And Result:

vertical line extending outside background with rounded corners

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Clipping is an expensive operation, and is only truly supported on Lollipop and higher.

If you're okay with Lollipop+ only, and really want to use a RelativeLayout, you can call myView.setClipToOutline(true). If your myView has a rounded background, this will tell the system to clip all children to that rounded shape.

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    myView.setClipToOutline(true);
}

If you need rounded corner clipping on pre-Lollipop versions, then the best thing to do is use an overlay to mask parts of the view you don't want to see. That is, create a drawable with opaque corners and a transparent center, and apply that on top of the views you want to clip. This won't actually clip your views, but it will provide the illusion of doing so.

More on this strategy here: https://www.techrepublic.com/article/pro-tip-round-corners-on-an-android-imageview-with-this-hack/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...