An android image on a list that thinks "outside" of the window

I want to have an ImageView that is part of a list box element, but it appears both inside and outside the line. Is it possible? if so, how? thank you very much in advance... alt text

+4
source share
3 answers

It works for me now, and I did not need to mess with Photoshop. I did all this using android xml.

the way to do this is to use the <layer-list> element and instead of using it without using the add-on, for example:

 <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:top="6dip" android:right="6dip" android:left="6dip"> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <corners android:bottomRightRadius="2dip" android:bottomLeftRadius="2dip" android:topLeftRadius="6dip" android:topRightRadius="6dip" /> <solid android:color="@color/list_view_outline" /> </shape> </item> <item android:top="8dip" android:right="8dip" android:left="8dip"> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <corners android:bottomRightRadius="2dip" android:bottomLeftRadius="2dip" android:topLeftRadius="6dip" android:topRightRadius="6dip" /> <solid android:color="@android:color/white" /> <stroke android:width="1dip" android:color="#BDBDBD" /> </shape> </item> 

then just use the standard line layout for the list line:

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/feed_list_row_content"> <ImageView android:id="@+id/author_image" android:layout_width="44dip" android:layout_height="44dip" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" android:src="@drawable/no_photo" android:layout_marginLeft="10dip" android:layout_marginTop="10dip" /> <TextView android:layout_width="wrap_content" android:layout_marginTop="10dip" android:layout_height="wrap_content" android:layout_toRightOf="@id/author_image" android:id="@+id/feed_message_content" android:layout_toLeftOf="@+id/action_button" /> <ImageView android:id="@id/action_button" android:src="@drawable/row_action" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_marginTop="20dip" /> 

Then I set the background in the getView () method of the custom list adapter, since the top and bottom rows are rendered differently than the middle rows.

 if(position == 0) { holder.contentLayout.setBackgroundResource(R.drawable.top_row); } else if(position == posts.size() - 1) { holder.contentLayout.setBackgroundResource(R.drawable.bottom_row); } else { holder.contentLayout.setBackgroundResource(R.drawable.inner_row); } 
+3
source

The answer is β€œnot quite,” at least obviously not the way you mean it, but you should be able to make your image off the line just by using a background image for list items that looks like the edge of the list has a few pixels from that places where he really is. Then you can simply align the element you want to overflow and add some right padding / margins for elements that you don't have.

+4
source

You must implement this with android:clipChildren="false" and android:clipToPadding="false" in the immediate representation of the parent, then android:clipChildren="false" in all groups of ancestor views and then put a negative field in the image view; those. android:layout_marginLeft="-10dp" .

It took me a while to figure out how they work, especially android:clipChildren="false" . Google says: "Determines whether a child is limited to drawing within its borders or not." The key point is that the "borders" of the child are not the borders of the parent view group, but the borders of the view are as defined using layout attributes, why do you need this before the ancestor tree.

+1
source

Source: https://habr.com/ru/post/1313445/


All Articles