Java 如何在android中向上移动水平居中视图? 我有这个XML

Java 如何在android中向上移动水平居中视图? 我有这个XML,java,android,xml,android-layout,layout,Java,Android,Xml,Android Layout,Layout,如何将开关\u v图像1dp从现在的位置向上移动 (它居中,但白色框有阴影,那么中心应该稍微向上) 像这样使用android:layout\u marginBottom=“1dp” I have this XML <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+i

如何将
开关\u v
图像1dp从现在的位置向上移动

(它居中,但白色框有阴影,那么中心应该稍微向上)


像这样使用
android:layout\u marginBottom=“1dp”

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>

像这样使用android:layout\u marginBottom=“1dp”

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>

试试这个,它会帮助你:

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

试试这个,它会帮助你:

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

试试这个

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

试试这个

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


查看9个补丁图像,您可以更好地设计这些元素,因为它的图像中有一个填充,并且您可以使用背景图像作为视图的真实背景。只是一个建议看看9个补丁图像,你可以更好地设计这些元素,因为它的图像中有一个填充,你可以使用背景图像作为视图的真实背景。仅仅是一个建议不起作用,因为`android:layout\u centerVertical=“true”`都德根据您的要求调整父视图,您要将其放置在哪个位置不起作用,因为`android:layout\u centerVertical=“true”`都德根据您的要求调整父视图,您要将其放置在哪个位置