1

这是我的布局代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:orientation="vertical" >





        <TableLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="5dp"
            android:gravity="center" >

            <TableRow
                android:id="@+id/tableRow1"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1" >

                <ImageView
                    android:id="@+id/imageView1"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_margin="5dp"
                    android:layout_weight="1"
                    android:background="@drawable/round"
                    android:scaleType="fitXY" />

                <ImageView
                    android:id="@+id/imageView2"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_margin="5dp"
                    android:layout_weight="1"
                    android:background="@drawable/roundp" 
                    android:scaleType="fitXY"/>
            </TableRow>

            <TableRow
                android:id="@+id/tableRow2"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_weight="1" >

                <ImageView
                    android:id="@+id/imageView3"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_margin="5dp"
                    android:layout_weight="1"
                    android:background="@drawable/roundp"
                    android:scaleType="fitXY" />

                <ImageView
                    android:id="@+id/imageView4"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_margin="5dp"
                    android:layout_weight="1"
                    android:scaleType="fitXY" />
            </TableRow>
        </TableLayout>

    </LinearLayout>

roundp.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle">
    <corners 
        android:topRightRadius="0dp"
        android:bottomLeftRadius="25dp"
        android:topLeftRadius="25dp"
        android:bottomRightRadius="0dp"/>

   <stroke 
       android:width="2dp"
       android:color="@color/red" />
   <solid 
       android:color="@color/white"/>


</shape>

圆形.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle">
    <corners 
        android:topRightRadius="25dp"
        android:bottomLeftRadius="0dp"
        android:topLeftRadius="0dp"
        android:bottomRightRadius="25dp"/>

   <stroke 
       android:width="2dp"
       android:color="@color/red" />
   <solid 
       android:color="@color/white"/>


</shape>

如果我没有在 ImageView 中放置任何图像,我可以看到带有圆角的空 ImageView,在放置图像圆角后,正常的矩形形状与图像一起显示。如何解决这个问题?

任何帮助将不胜感激。

4

4 回答 4

0

您一直在使用 layout_weight 属性,但没有在任何地方使用 weight_sum 属性。

于 2013-03-08T08:14:31.023 回答
0

将渐变放入形状 xml..

<gradient
        android:angle="270"
        android:endColor="#fddd"
        android:startColor="#ffff" />
于 2012-10-17T09:20:19.947 回答
-1

对于回合,你可以添加android:padding来显示边界。

但是,对于roundp,除非通过代码 java 处理图像,否则我不知道要修复它。

于 2012-10-17T07:21:17.820 回答
-1

有为图像添加圆角的代码

public static Bitmap toRoundCorner(Bitmap bitmap, int pixels) {  

    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);  

    Canvas canvas = new Canvas(output);  

    final int color = 0xff424242;  

    final Paint paint = new Paint();  

    final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());  

    final RectF rectF = new RectF(rect);  

    final float roundPx = pixels;  

    paint.setAntiAlias(true);  

    canvas.drawARGB(0, 0, 0, 0);  

    paint.setColor(color);  

    canvas.drawRoundRect(rectF, roundPx, roundPx, paint);  

    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));  

    canvas.drawBitmap(bitmap, rect, rect, paint);  <br>
    return output;  

}
于 2012-10-17T08:37:05.457 回答