Android的XML圆润剪切的边角边角、圆润、Android、XML

2023-09-12 02:53:56 作者:等你浪够逼也烂了

我已经安装具有以下绘制背景的LinearLayout:

I've setup a LinearLayout with the following drawable background:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <corners android:radius="10dp" />
    <solid android:color="#CCFFFFFF"/>
</shape>

我遇到的问题是的LinearLayout中我有一个位于底部的它的父另一个的LinearLayout元素。因为不具有圆角其角延伸经过父母左下角和右下角。

The problem I'm having is within the LinearLayout I have another LinearLayout element that sits at the bottom of it's parent. Since that doesn't have rounded corners its corners extend past the parents bottom left and right corners.

在孩子的LinearLayout的绘制背景是这样的:

The drawable background on the Child LinearLayout looks like this:

<?xml version="1.0" encoding="utf-8"?>
<bitmap
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:src="@drawable/pedometer_stats_background" 
    android:tileMode="repeat"   
/>

这个问题看起来是这样的: http://kttns.org/hn2zm 设备上的非剪裁更为明显。

The issue looks like this: http://kttns.org/hn2zm on the device the non-clipping is more apparent.

什么是完成裁剪最好的方法是什么?

What is the best method to accomplish the clipping?

推荐答案

怎么这样你描述的声音:

What your describing sounds like this:

<LinearLayout android:shape="rounded">
   <LinearLayout android:background="@drawable/pedometer_stats_background">
   </LinearLayout>
</LinearLayout>

和内布局是推圆角外,因为它不是圆形的。你必须圆你的位图的角落。如果你有一个重复的位图,你会想看看定义九补丁绘制。圆你的角落,然后定义可扩展图形的部分。

And the inner layout is pushing outside the rounded corners because it isn't rounded. You'll have to round the corners of your bitmap. If you have a repeating bitmap you'll want to look at defining a nine-patch drawable. Round your corners then define the portion of the graphic that can expand.

http://developer.android.com/guide/topics/resources/drawable-resource.html#Shape

这将会是很好,如果我们能位图只是添加到形状绘制并为皮肤无论形状,我们正在绘制了该应用。而且,我如果你知道你在做什么,你可以创建一个形状子类,绘制一个位图赌,但是这不包括在Android的开箱即用的不幸。

It'd be nice if we could just add a bitmap to the shape drawable and have that be applied as a skin over whatever shape we're drawing. And, I bet if you know what your doing you could create a Shape subclass that draws a bitmap, but that's not included in Android out of the box unfortunately.