代码之家  ›  专栏  ›  技术社区  ›  Mariusz

从顶部而不是底部裁剪视图

  •  0
  • Mariusz  · 技术社区  · 9 年前

    我希望当视图不适合其容器时,从顶部而不是从底部裁剪视图。这是我的布局:

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

    现在,my_view的底部20dp被裁剪。我应该怎么做才能裁剪my_view的顶部20dp而不是底部?

    1 回复  |  直到 9 年前
        1
  •  1
  •   Aziz    9 年前

    您可以这样使用视图的布局重力来完成此操作

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