Java 将图像视图转换为圆形线性布局

Java 将图像视图转换为圆形线性布局,java,android,xml,android-layout,material-design,Java,Android,Xml,Android Layout,Material Design,我有一些关于这个圆形线性布局的图像视图。以下是我的简单代码: 但是图像角覆盖了LinearLayout角,如果LinearLayout没有看到,则最终覆盖了边框。 我怎样才能修好它?我需要将一些imageview设置为线性布局,还需要将边框和圆角设置为linearlayout。 谢谢 编辑:我想要这样的东西(圆角布局中有四个图像): 首先,您需要创建一个简单的可绘制图形并使用此代码。您可以根据自己的选择更改宽度、笔划和颜色。半径也可以简化为:radius=dpValue ?xml vers

我有一些关于这个圆形线性布局的图像视图。以下是我的简单代码:


但是图像角覆盖了LinearLayout角,如果LinearLayout没有看到,则最终覆盖了边框。
我怎样才能修好它?我需要将一些imageview设置为线性布局,还需要将边框和圆角设置为linearlayout。
谢谢

编辑:我想要这样的东西(圆角布局中有四个图像):

首先,您需要创建一个简单的可绘制图形并使用此代码。您可以根据自己的选择更改宽度、笔划和颜色。半径也可以简化为:radius=dpValue

?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <solid android:color="#ffffffff"/>    

    <stroke android:width="3dp"
            android:color="#ff000000"/>

<corners android:bottomRightRadius="7dp" android:bottomLeftRadius="7dp" 
 android:topLeftRadius="7dp" android:topRightRadius="7dp"/> 
</shape>
我可能会尝试让你的图像视图包装你的内容。您还应该尝试在ImageView的高度上设置0dp


希望这有帮助。

您可以在drawable文件夹中创建一个XML文件。例如,将其命名为shape.xml

<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"   >

<solid
    android:color="#888888" >
</solid>

<stroke
    android:width="2dp"
    android:color="#C4CDE0" >
</stroke>

<padding
    android:left="5dp"
    android:top="5dp"
    android:right="5dp"
    android:bottom="5dp"    >
</padding>

<corners
    android:radius="11dp"   >
</corners>

设置直线布局

<LinearLayout
android:layout_width="128dp"
android:layout_height="128dp"
android:id="@+id/point_image_table1"
android:orientation="vertical"
android:drawable="@drawable/image_view_style"
android:layout_below="@+id/repoint_p_name"
android:weightSum="4">
</LinearLayout>


希望这有帮助……

我建议您将cardview与多个图像一起使用。获得拼贴视图将很容易,请尝试这种方式

<android.support.v7.widget.CardView
        android:layout_width="300dp"
        android:layout_height="300dp"
        android:layout_marginTop="10dp"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        card_view:cardCornerRadius="10dp">

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="300dp"
        android:layout_height="300dp">



        <LinearLayout
            android:id="@+id/left_container"
            android:layout_alignParentTop="true"
            android:layout_alignParentLeft="true"
            android:layout_width="150dp"
            android:layout_height="300dp"
            android:orientation="vertical">

            <ImageView
                android:id="@+id/dog"
                android:layout_width="150dp"
                android:layout_height="0dp"
                android:layout_weight="1"

                android:background="@drawable/mmm" />


            <ImageView
                android:id="@+id/bottom_left_image"
                android:layout_width="150dp"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:layout_marginTop="5dp"
                android:background="@drawable/mmm" />

        </LinearLayout>

        <LinearLayout
            android:id="@+id/right_container"
            android:layout_width="150dp"
            android:layout_height="300dp"
            android:layout_marginLeft="5dp"
            android:layout_toRightOf="@+id/left_container"
            android:orientation="vertical">

            <ImageView
                android:id="@+id/top_right_image"
                android:layout_width="150dp"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:background="@drawable/mmm" />


            <ImageView
                android:id="@+id/bottom_right_image"
                android:layout_width="50dp"
                android:layout_height="0dp"
                android:layout_weight="0"
                android:background="@drawable/mmm" />

        </LinearLayout>

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/transparent"/>

    </RelativeLayout>

    </android.support.v7.widget.CardView>

谢谢您的回复。我已经使用了这个解决方案。但是图像覆盖了LinearLayout的边界。你能用你活动的截图更新你的问题吗?我想知道你所说的“图像覆盖线性布局的边界”是什么意思。我确实理解,但我想看看它,这样我就可以思考如何解决它。为线性布局提供填充,这样我就可以想象您提供的图像是您创建的虚拟版本,而不是实际的XML渲染?如果是这样的话,我认为您需要将具有半径的背景添加到线性布局中
android:background=“@drawable/yourDrawableName”
注意我如何使用background而不是
android:drawable
旁注-我看到你有野生动物摄影奖的照片!很酷的东西:Dso基本上你想要像容器圆角拼贴这样的东西吗?@MohammedAtif是的。谢谢你的回复,我已经用过这个解决方案了。但它不起作用,就像一个符咒!这正是我想要的。感谢您的帮助..快乐编码…:)
<LinearLayout
android:layout_width="128dp"
android:layout_height="128dp"
android:id="@+id/point_image_table1"
android:orientation="vertical"
android:drawable="@drawable/image_view_style"
android:layout_below="@+id/repoint_p_name"
android:weightSum="4">
</LinearLayout>
<android.support.v7.widget.CardView
        android:layout_width="300dp"
        android:layout_height="300dp"
        android:layout_marginTop="10dp"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        card_view:cardCornerRadius="10dp">

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="300dp"
        android:layout_height="300dp">



        <LinearLayout
            android:id="@+id/left_container"
            android:layout_alignParentTop="true"
            android:layout_alignParentLeft="true"
            android:layout_width="150dp"
            android:layout_height="300dp"
            android:orientation="vertical">

            <ImageView
                android:id="@+id/dog"
                android:layout_width="150dp"
                android:layout_height="0dp"
                android:layout_weight="1"

                android:background="@drawable/mmm" />


            <ImageView
                android:id="@+id/bottom_left_image"
                android:layout_width="150dp"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:layout_marginTop="5dp"
                android:background="@drawable/mmm" />

        </LinearLayout>

        <LinearLayout
            android:id="@+id/right_container"
            android:layout_width="150dp"
            android:layout_height="300dp"
            android:layout_marginLeft="5dp"
            android:layout_toRightOf="@+id/left_container"
            android:orientation="vertical">

            <ImageView
                android:id="@+id/top_right_image"
                android:layout_width="150dp"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:background="@drawable/mmm" />


            <ImageView
                android:id="@+id/bottom_right_image"
                android:layout_width="50dp"
                android:layout_height="0dp"
                android:layout_weight="0"
                android:background="@drawable/mmm" />

        </LinearLayout>

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/transparent"/>

    </RelativeLayout>

    </android.support.v7.widget.CardView>