2015-04-03 61 views
0

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

我需要什么:

  • ImageView的垂直居中对齐和左
  • 一半的ImageView的是可见的(translationX = -50%)
  • 当抽屉开始滑动,其余imageView是可见的

我试图做到这一点,但当拖动抽屉时图像总是被剪切掉。

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%可见。

+0

请显示一些代码。 – natario 2015-04-03 08:30:19

+0

好的 - 现在你在屏幕左侧有这个半个图标。当抽屉从左侧进入时,图标将被完全覆盖。你想要做什么? – natario 2015-04-03 08:43:31

+0

我希望ImageView(图标)与抽屉一起移动,所以当抽屉完全打开时,我会看到完整的图像。 – Bugdr0id 2015-04-03 08:47:06

回答

0

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