Android - 设置抽屉图标一半可见

时间:2015-04-03 08:27:55

标签: android drawer

我有一个抽屉的自定义图标,我想将它垂直放在活动上,X轴移动-50%,所以当抽屉打开时,其他50%是可见的。

我需要什么:

  • ImageView垂直居中并向左对齐
  • 此imageView的一半可见(translationX = -50%)
  • 当抽屉开始滑动时,图像的其余部分可见

我试过这样做,但拖动抽屉时图像总是会被切断。

XML:MainActivity

 <android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout 
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ImageView
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:layout_marginLeft="-50dp"
            android:src="@drawable/drawer_icon" />
    </RelativeLayout>

    <!-- The navigation drawer -->
    <RelativeLayout
        android:layout_width="250dp"
        android:layout_height="match_parent"
        android:layout_gravity="start">

        <ListView
            android:id="@+id/left_drawer"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#00ff00"
            android:choiceMode="singleChoice"
            android:divider="@android:color/transparent"
            android:dividerHeight="0dp" />

    </RelativeLayout>
</android.support.v4.widget.DrawerLayout>

一旦我拖动抽屉,我希望隐藏在左侧的50%开始可见,所以当抽屉打开时,图标是100%可见。

1 个答案:

答案 0 :(得分:0)

尝试从imageView中删除android:layout_marginLeft =“ - 50dp”代码行。