3

enter image description here机器人 - 圆形线性布局角球FILL_PARENT的TextView重叠

这是我需要我的布局的顶部

enter image description here

这是我居然有

会有一个简单的选项,我目前没有计算。

可绘制圆角的

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <solid android:color="#E9E9E9"/> 
    <stroke android:width="4dip" android:color="#B1BCBE" /> 
    <corners android:radius="10dip"/> 
    <padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" /> 
</shape> 

布局

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/home_root" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/rounded_layout" > 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" > 

     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="@string/filter_title" 
      android:background="@android:color/black" 
      android:textColor="@android:color/white" 
      android:padding="10dp" 
      android:textSize="20sp" /> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:padding="15dp" > 

      <Spinner 
       android:id="@+id/sp_intorno_a_me_proximity" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="10dp" 
       android:spinnerMode="dialog" /> 
      . 
      . 
      . 
      <EditText 
       android:id="@+id/et_intorno_a_me_username" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="10dp" 
       android:textSize="20sp" 
       android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" 
       android:hint="@string/agentNumber" /> 

      <LinearLayout 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:orientation="horizontal" 
       android:layout_marginTop="20dp" 
       android:layout_marginBottom="10dp" 
       android:weightSum="1" > 

       <Button 
        android:id="@+id/btn_intorno_a_me_close_search" 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:layout_weight="0.5" 
        android:text="@string/annulla" 
        style="@style/HelianButtonRed" 
        android:textColor="@android:color/white" /> 

       <Button 
        android:id="@+id/btn_intorno_a_me_search" 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:layout_weight="0.5" 
        android:text="@string/find" 
        style="@style/HelianButtonGreen" /> 
      </LinearLayout> 
     </LinearLayout> 
    </LinearLayout> 

</ScrollView> 

我已经尝试了绘制移至第一的LinearLayout孩子。

如何防止文本视图隐藏圆角?

+0

为什么不在第二个LinearLayout中声明标题TextView?通过这种方式,textView背景不会覆盖你的圆角。 – Manishika

+0

因为结果将被填充,因为** android:padding =“15dp”** secondo线性布局。我可以避免填充单个视图吗? –

回答

2

在你的TextView中尝试类似这样的背景。 用以下数据

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <solid android:color="#000000"/> 
    <stroke android:width="4dip" android:color="#B1BCBE" /> 
    <corners 
     android:topLeftRadius="10dip" 
     android:topRightRadius="10dip" 
     android:bottomLeftRadius="0dip" 
     android:bottomRightRadius="0dip" 

     /> 
    <padding android:left="0dip" android:top="0dip" android:right="0dip"     
     android:bottom="0dip" /> 

</shape> 
+0

我还没有尝试过,我确定这个解决方法可行,但我想要一个更优雅的解决方案,不要强迫我复制半径和颜色两次(一个用于布局绘制,一个用于按钮画)。 我想概括一下它... 谢谢你反正给我的时间! –

+0

其实你不能删除填充到一个视图,如果你有填充到parentLayout.But你可以做的是把TextView放在一个LinearLayout没有任何填充,并把两个textView的LinearLayout和LinearLayout2在一个LinearLayout内,并给这个LinearLayout的背景。这种方式你的TextView将不会有填充 – Manishika

+0

我知道这是一个不好的做法。但你应该试试看。 – Manishika

3

随着Manishika的帮助下创建的TextView新绘制的.xml(我投了你的答案[为我做一样的!:)])我张贴我的问题的解决方案!

有了这个父圆角风格:

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <solid android:color="#E9E9E9"/> 
    <stroke android:width="4dip" android:color="#B1BCBE" /> 
    <corners android:radius="10dip"/> 
    <padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" /> 
</shape> 

我们需要一个特定的绘制连接到TextView的(或者你需要的任何视图)。

这里是用于特技可绘制:

我减去2 d

<corners 
     android:topLeftRadius="8dip" 
     android:topRightRadius="8dip" 
     android:bottomLeftRadius="0dip" 
     android:bottomRightRadius="0dip" /> 
</shape> 

记住!!

图形布局(预览)将显示正确的舍入!您需要在设备上进行测试(如果没有设备,则需要在模拟器上进行测试)。