Android绘图线有保证金

时间:2016-04-05 10:41:24

标签: android drawable shape layer-list

所以,我设法创建了一个只有一面的形状(矩形)。现在,我希望一方有边距和边距。现在它看起来像这样:

Right now it looks like this:

这就是它应该是什么样子(不介意颜色):

enter image description here

现在,我有一行代码:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

<item
    android:left="-55dp"
    android:right="-55dp"
    android:top="-55dp">
    <shape android:shape="rectangle" >
        <solid android:color="@android:color/transparent" />

        <stroke
            android:width="5dp"
            android:color="@color/text" />
    </shape>
</item>

如何实现这一目标?

textviews的布局。

 <LinearLayout
        android:id="@+id/picture_activity_linear"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/layout_margin"
        android:layout_marginLeft="@dimen/layout_margin"
        android:layout_marginRight="@dimen/layout_margin"
        android:background="@color/background"
        android:orientation="vertical"
        android:visibility="visible">


        <TextView
            android:id="@+id/picture_activity_take_new"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/shape_text_line"
            android:drawableStart="@drawable/ic_profilepicture_takephoto"
            android:gravity="center"
            android:padding="@dimen/layout_padding"
            android:text="Take a new picture"
            android:textColor="@color/text"
            android:textSize="@dimen/large_text_size"/>

        <TextView
            android:id="@+id/picture_activity_select_from_gallery"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:drawableStart="@drawable/ic_profilepicture_addphoto"
            android:gravity="center"
            android:padding="@dimen/layout_padding"
            android:text="Select new from gallery"
            android:textColor="@color/text"
            android:textSize="@dimen/large_text_size"/>


        <TextView
            android:id="@+id/picture_activity_remove_photo"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:drawableStart="@drawable/ic_profilepicture_delete"
            android:gravity="center"
            android:padding="@dimen/layout_padding"
            android:text="Remove photo"
            android:textColor="@color/text"
            android:textSize="@dimen/large_text_size"/>


    </LinearLayout>

1 个答案:

答案 0 :(得分:1)

我认为您正在使用recyclerview。对于recyclerview,您需要具有单行布局。

<LinearLayout>
    height, width, id

    <TextView>
         width = "match_parent"
         height, id

    <LinearLayout>
         android:id="@+id/line"
         android:height="2dp"
         android:width="match_parent"
         android:layout_marginLeft="whatever_you_need"
         android:layout_marginRight="whatever_you_need"
         android:background="some_color" />

</LinearLayout>

所以在这里,您不必每次都手动添加该行 有一个问题,即该行将位于最后一行之下。我相信你想删除它。

在适配器

String[] itemList = {"Take a new Picture", "Select from Gallery",...};

在recyclerview适配器的viewholder类中:

line = (LinearLayout) itemView.findViewById(R.id.line);

在您的onBindViewHolder中进行recyclerview。在这里,我们确定最后一行,然后隐藏下划线。

if(position == itemList.length - 1){  //position starts from 0
    holder.line.setVisibility(View.GONE);
}

现在看起来像你想要的那样

相关问题