1

ということで、なんとか一辺だけの形(長方形)を作ることができました。今、私はその片側に右マージンと左マージンを持たせたいと思っています。現在、次のようになっています。

現在、次のようになっています。

そして、これは次のように見えるはずです(色は気にしないでください):

ここに画像の説明を入力

今、私は行のコードを持っています:

<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>

これを達成する方法は?

テキストビューのレイアウト。

 <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>
4

1 に答える 1

1

あなたはrecyclerviewを使用していると思います。recyclerview の場合、1 行のレイアウトが必要です。

<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>

ここでは、毎回手動で行を追加する必要はありません。1 つの問題があります。つまり、行が最後の行の下に表示されます。あなたはそれを削除したいと思います。

アダプター内

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

recyclerview アダプターのビューホルダー クラスで:

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

recyclerview の onBindViewHolder で。ここでは、最後の行を特定し、下線を非表示にします。

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

今、これはあなたが望むように見えます

于 2016-04-05T11:38:40.927 に答える