java - 如何将图像放在android中另一个图像上方的中央?

标签 java android xml animation layout

我想创建这样的布局:

enter image description here

我有 3 个不同的图像:背景、白色方 block 和 V 形符号。

如果我想让盒子左右移动,我怎样才能像照片中那样放置它们

当触发 onClick 时,V 符号淡入\淡出。

我试过:

   <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="right"
    android:background="@drawable/off_background">


             <ImageView
            android:id="@+id/handle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
             android:src="@drawable/handle"
            android:scaleType="centerInside" />

    <ImageView android:id="@+id/switch_v"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:src="@drawable/switch_v"
        android:layout_gravity="center"
        android:scaleType="centerInside"/>



</RelativeLayout>

它给了我正确的顺序,但没有正确摆姿势:

enter image description here

最佳答案

您必须使用layout_align 来解决这个问题。我已经针对您的示例对其进行了测试,它工作正常。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:background="@drawable/off_background" >

<ImageView
    android:id="@+id/handle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:scaleType="centerInside"
    android:src="@drawable/handle" />

<ImageView
    android:id="@+id/switch_v"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@id/handle"
    android:layout_alignTop="@id/handle"
    android:layout_alignBottom="@id/handle"
    android:layout_alignRight="@id/handle"
    android:layout_gravity="center"
    android:scaleType="centerInside"
    android:src="@drawable/switch_v" />
</RelativeLayout>

关于java - 如何将图像放在android中另一个图像上方的中央?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19660793/

相关文章:

android - CustomListView后台问题

java - Android 上的小区广播支持?

android - 软键盘覆盖EditText下方的TextView

C#将xml属性转换为元素

android - 微调器从顶部而不是底部打开

java - USB 设备在打开应用程序后重新连接之前无法使用

java - 当条目超过饱和级别时,Java 8 HashMap 中如何创建树

java - Eclipse:将 Maven 配置添加到快速链接

java - 如何在主java中调用Keypress函数

android - okhttp 多部分登录拦截器