简体   繁体   English

圆角的线性布局在拐角处留有多余的空间

[英]Rounded linear layout leaving extra space on corners

i am creating a rounded linear layout with some buttons and textviews, i have used a custom selector as background of layout. 我正在创建带有一些按钮和textviews的圆角线性布局,我使用了自定义选择器作为布局背景。 My problem is that layout have extra space on corners how to remove this? 我的问题是布局在角上有多余的空间如何将其删除? any help will be appreciated here is my code 任何帮助将不胜感激,这是我的代码

<?xml version="1.0" encoding="utf-8"?>
<shape 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" android:padding="10dp"
    >
    <solid android:color="#FFFFFF"/>
    <corners
        android:bottomRightRadius="15dp"
        android:bottomLeftRadius="15dp"
        android:topLeftRadius="15dp"
        android:topRightRadius="15dp"
        />
    <stroke android:width="2dip"
            android:color="@color/#275D69"/>
</shape>

Layout: 布局:

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/selector"
    />

Current output: 电流输出: 在此处输入图片说明

Dont want that space where i have placed red marks. 不想在我放置红色标记的空间。

With below code you have rounded background with least space on corner 使用以下代码,您可以使背景变圆且角上的空间最小

 <?xml version="1.0" encoding="utf-8"?>
   <shape xmlns:android="http://schemas.android.com/apk/res/android"
      android:padding="10dp"
      android:shape="rectangle">
    <solid android:color="#FFFFFF" />
    <corners android:radius="5dp" />
    <stroke
      android:width="2dip"
      android:color="#275D69" />
   </shape>

this may include space on corner but it's too low. 这可能包括拐角处的空间,但空间太小。

just reduce radius value. 只需减小radius值即可。

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
   android:shape="rectangle" android:padding="10dp">
   <solid android:color="#FFFFFF"/>
   <corners
      android:bottomRightRadius="15dp"
      android:bottomLeftRadius="15dp"
      android:topLeftRadius="15dp"
      android:topRightRadius="15dp" />
   <stroke android:width="0dip"
    android:color="@color/#275D69"/>
</shape>
<corners android:radius="6dip" />

Put corner radius whatever you want. 根据需要设置corner radius

Here is a solution you need to follow: 这是您需要遵循的解决方案:

<?xml version="1.0" encoding="utf-8"?>
   <shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" android:padding="10dp">

      <solid android:color="#FFFFFF"/>
          <corners
            android:bottomRightRadius="15dp"
            android:bottomLeftRadius="15dp"
            android:topLeftRadius="15dp"
            android:topRightRadius="15dp" />

      <stroke
            android:width="2dip"
            android:color="#275D69"/>

 </shape>

Now in main xml 现在在主xml中

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:orientation="vertical">

   <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:margin="10dp"
        android:background="@drawable/selector"
        android:orientation="vertical">
   </LinearLayout>

</LinearLayout>

Problem solved! 问题解决了!

Try to use this approach, is not the most clear solution but for me works: 尝试使用这种方法,不是最清晰的解决方案,但对我而言有效:

Create a Layout container with transparent background, and use it as a container of your rounded layout 创建具有透明背景的布局容器,并将其用作圆形布局的容器

<LinearLayout
.....
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@android:color/transparent"
......>

  <LinearLayout

    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/selector"
    android:orientation="vertical">

     <!-- content of the rounded ll -->
   </LinearLayout>
</LinearLayout>

The white spaces should be disappeared 空白区域应消失

You can make rounded corners using cardView 您可以使用cardView制作圆角

 <android.support.v7.widget.CardView 
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:layout_marginTop="6dp"
app:cardCornerRadius="5dp"
app:cardBackgroundColor="#D3D3D3"
app:cardPreventCornerOverlap="false"
card_view:cardPreventCornerOverlap="false">

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="3dp" />

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM