【问题标题】:Bring view to the front prprogrammaticly以编程方式将视图带到前面
【发布时间】:2015-08-09 13:28:50
【问题描述】:

当单击 imageButton 时,我正在使用 frameLayout 并尝试以编程方式将视图 on 引入另一个视图。我使用 Frame Layout 是因为有人告诉我它可以让你看到彼此。但是,当单击按钮时,imageView 在另一个视图后面消失,而不是在前面。 这是我的布局 - “hole”是 imageButton,每当单击它时,imageView “goola”都需要在其上移动。

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="${relativePackage}.${activityClass}" >

<ImageButton
    android:id="@+id/hole"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
            android:layout_marginLeft="100dp"
                    android:background="@android:color/transparent"
    android:src="@drawable/home0" />

<ImageView
    android:id="@+id/goola"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="10dp"
    android:src="@drawable/goola" />

这里是JAVA(onClick方法)

@Override
public void onClick(View v)
{
    ImageButton b=(ImageButton)v;
    int[] location = new int[2];     
    b.getLocationOnScreen(location);

     float startX = location[0];
     float startY = location[1];
        goola.setX(startX);
        goola.setY(startY);
}

如果有解决方案的人可以写一个好的答案,我将不胜感激! 提前非常感谢:)

【问题讨论】:

    标签: android view imageview imagebutton android-framelayout


    【解决方案1】:

    您可以尝试在适当的视图上调用View#bringToFront()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-09
      • 2017-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多