Elad Benda2
Elad Benda2

Reputation: 15472

how can I move up a bit a horizontal centered view in android?

I have this XML

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/switch_bg"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="0dp" >

    <ImageView
        android:id="@+id/switch_bg2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
            android:layout_alignParentLeft="true"
    android:layout_centerVertical="true"
        android:src="@drawable/switch_bg_off" />

<RelativeLayout
    android:id="@+id/switch_handle"
    android:layout_width="50dp"
    android:layout_marginTop="7dp"
    android:layout_height="50dp"
    android:layout_alignParentLeft="true"
    android:background="@drawable/switch_handle"
    android:padding="0dp" >

    <ImageView
        android:id="@+id/switch_v"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:src="@drawable/switch_v"
        android:visibility="visible" />

</RelativeLayout>

</RelativeLayout>

how can I move the switch_v image 1dp up from where it is now?

(it's centered but the white box has shadow, then the center should be a bit upper)

enter image description here

Upvotes: 1

Views: 267

Answers (3)

Bhanu Sharma
Bhanu Sharma

Reputation: 5145

Try this, it should help you:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/switch_bg2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/switch_bg_off" >

    <ImageView
        android:id="@+id/switch_v"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:padding="2dp"
        android:src="@drawable/switch_v"
        android:visibility="visible" />

</RelativeLayout>

Upvotes: 1

try this

<ImageView
        android:id="@+id/switch_bg2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerInParent="true"
        android:layout_centerVertical="true"
        android:src="@drawable/ic_launcher"
         />

    <ImageView
        android:id="@+id/switch_v"
        android:layout_above="@+id/hiddenView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:src="@drawable/ic_launcher"
        android:visibility="visible"
         />
    <View
        android:id="@+id/hiddenView"
        android:layout_width="wrap_content"
        android:layout_height="1dp"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:visibility="invisible"
         />

Upvotes: 0

Mohsen fallahi
Mohsen fallahi

Reputation: 917

use android:layout_marginBottom="1dp" like this

<ImageView
    android:id="@+id/switch_v"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:src="@drawable/switch_v"
    android:visibility="visible"
    android:layout_marginBottom="1dp"  />

Upvotes: 0

Related Questions