android中带有弯曲侧边的自定义形状线性布局
我正在尝试制作一个定制形状的线性布局,如下图所示 我试着只使一面弯曲。尝试使用“拐角半径”,但外观与上面的不同 已尝试此背景形状,如下所示:-android中带有弯曲侧边的自定义形状线性布局,android,android-xml,android-drawable,android-shape,Android,Android Xml,Android Drawable,Android Shape,我正在尝试制作一个定制形状的线性布局,如下图所示 我试着只使一面弯曲。尝试使用“拐角半径”,但外观与上面的不同 已尝试此背景形状,如下所示:- <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#3F51B5" />
<padding
android:bottom="7dp"
android:left="7dp"
android:right="7dp"
android:top="7dp" />
<corners
android:bottomLeftRadius="50dp"
android:bottomRightRadius="50dp"
android:topLeftRadius="0dp"
android:topRightRadius="0dp" />
</shape>
它只圆角,并且随着值的增加,形状不会被保留,它变得太圆了。我想要曲线而不是圆角您可以在value-dimension.xml fime中设置尺寸,然后在您的线性布局的xml中设置它,它将给出如下结果
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid
android:color="#FFFF00" />
<padding android:left="7dp"
android:top="7dp"
android:right="7dp"
android:bottom="7dp" />
只需在可绘制文件夹中创建一个xml文件,设置所需的尺寸,然后通过线性布局调用它在可绘制文件夹中创建一个形状文件,例如:my_shape.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:bottomLeftRadius="100dp"
android:bottomRightRadius="100dp"
android:topLeftRadius="0dp"
android:topRightRadius="0dp" />
<padding
android:bottom="0dp"
android:left="0dp"
android:right="0dp"
android:top="0dp" />
<stroke
android:width="0.5dp"
android:color="@color/theme_red" />
<solid android:color="@color/white" />
</shape>
然后在布局中添加此形状作为背景。e、 g:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/my_shape"
android:orientation="horizontal">
</LinearLayout>
我所做的是
创建一个可绘制的allowaccess\u按钮\u normal.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<solid android:color="@color/colorPrimary"/>
</shape>
</item>
</selector>
试试下面的布局
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:background="#fefefe"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:background="@color/colorPrimary"
android:layout_height="110dp">
</RelativeLayout>
<ImageView
android:layout_marginTop="85dp"
android:src="@drawable/allowaccess_button_normal"
android:layout_width="match_parent"
android:layout_height="50dp" />
</RelativeLayout>
已经很晚了,但这是为未来的搜索者准备的。 我认为这是最完美的解决方案。使用“下方向量”获得自定义形状的底部曲线布局
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="100.0"
android:viewportWidth="200.0">
<path
android:fillColor="#YOUR_FAVORITE_COLOR"
android:pathData="M200,0H0v4.5h0v75.8h0c17.8,10.2 56,17.2 100.5,17.2c44.5,0 81.6,-7 99.5,-17.2h0V4.5h0V0z" />
shape\u curve.xml
使用
您可以使用此曲线阴影创建图像,并可以添加为布局的背景。我不确定它在所有分辨率下是否都相同,因此我避免了这种情况。会吗?你可以使用dimen来解决所有的问题,并且使它很容易工作。@SumeetDarade你能解决这个问题吗??你是如何做到这一点的?很抱歉没有得到它,但你能举个例子吗?我不确定你们说的是什么尺寸,因为我说我试着添加了半径。它看起来不像图中的形状。我想线条是曲线,我想你们应该用背景图片。首先,根据需要设计一个图像。然后在布局中使用它作为背景。是的,您能建议任何分辨率,以使其在所有设备上看起来相同吗?您应该从mdpi屏幕开始图像设计,然后设计屏幕的其余部分,如hdpi、xhdpi、xxhdpi等,并且必须遵循屏幕设计比例。遵循此操作并将其与ImageView scaleType=fitXY一起使用
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="100.0"
android:viewportWidth="200.0">
<path
android:fillColor="#YOUR_FAVORITE_COLOR"
android:pathData="M200,0H0v4.5h0v75.8h0c17.8,10.2 56,17.2 100.5,17.2c44.5,0 81.6,-7 99.5,-17.2h0V4.5h0V0z" />