Mariusz February 2016

Crop view from top instead of bottom

I want a view to be cropped from the top instead from the bottom when it doesn't fit into its container. This is my layout:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height=“100dp”

    <View
        android:id="@+id/my_view"
        android:layout_width="match_parent"
        android:layout_height=“80dp">

</FrameLayout>

Now bottom 20dp of my_view are cropped. What should I do to crop the top 20dp of my_view instead of the bottom part?

Answers


Aziz February 2016

You can do this using layout gravity of your view like this

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
         android:layout_width="wrap_content"
         android:background="#FFFFFF"
         android:layout_height="100dp">

<View
    android:id="@+id/my_view"
    android:layout_width="match_parent"
    android:layout_gravity="bottom"
    android:background="#000000"
    android:layout_height="80dp"/>

Post Status

Asked in February 2016
Viewed 2,956 times
Voted 13
Answered 1 times

Search




Leave an answer