0

I have a custom icon for a drawer and i want to place it vertically centred on activity with a shift of X axis -50%, so when the drawer opens the other 50% is visible.

what do i need:

  • ImageView vertically centred and aligned to left
  • Half of this imageView is visible ( translationX = -50% )
  • When the drawer starts to slide, the rest of the imageView is visible

I have tried to do this, but the image is always cut when the drawer is dragged.

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>

Once i drag the drawer i expect that the 50% hidden on left side start to be visible, so when the drawer is open the icon is 100% visible.

Bugdr0id
  • 2,962
  • 6
  • 35
  • 59
  • Please show some code. – natario Apr 03 '15 at 08:30
  • OK - now you have this half icon on the left side of the screen. When the drawer comes in from left, the icon will get completely covered. What do you want to do instead? – natario Apr 03 '15 at 08:43
  • I want the ImageView (icon) to shift together with the drawer, so when the drawer is totally open i see the full image. – Bugdr0id Apr 03 '15 at 08:47
  • So shift together *plus* an additional shift to show the actually-hidden half of the image? – natario Apr 03 '15 at 08:51
  • yes, if i initially shift the image -50%, when i drag i want to see the other 50% left overlaying the drawer – Bugdr0id Apr 03 '15 at 08:53
  • Ok, now it is perfectly clear. I would suggest to edit your question with these info. – natario Apr 03 '15 at 08:56
  • Is using 2 images (one with half the design and one with the full design) an option? – Phantômaxx Apr 03 '15 at 09:09
  • i explored that option, but sometimes there seems to be a delay so the image seems to be split in half. It doesn't give a smooth animation. – Bugdr0id Apr 03 '15 at 09:13

1 Answers1

0

Try removing android:layout_marginLeft="-50dp" line of code from the imageView.