android - 将按钮从相对布局更改为线性布局奇怪的副作用

标签 android xml multithreading layout

今天发生在我身上的最奇怪的事情导致数小时的沮丧和愤怒管理问题。

我有一个可以运行的 Android 幻灯片应用程序。但是,我对按钮(在相对布局中)不满意,并将它们移至线性布局。但是,在运行我的应用程序时,按钮的行为发生了交换(即按钮 1 执行按钮 2 的工作,反之亦然)。我能够通过更改其中一个按钮的 ID 来解决这个问题,而不是全部(这没有用)。与此相关的还有,当我切换方向时,我的应用程序开始崩溃。当我有相对布局时它以前工作过。 (我正在使用处理程序更改幻灯片的 UI)

我无法解决这个问题,所以我恢复了我的相对布局,但我首先想知道这是怎么发生的。

有效的布局:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >



    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_centerInParent="true"
        android:contentDescription="@string/imageView"
        android:scaleType="centerInside"
        android:src="@drawable/image1" />

    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:textAppearance="?android:attr/textAppearanceMedium" />



        <ImageButton
            android:id="@+id/startStop"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:contentDescription="@string/startStop"
            android:src="@drawable/ic_menu_slideshow" />

        <ImageButton
            android:id="@+id/next"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="false"
            android:layout_toRightOf="@+id/startStop"
            android:contentDescription="@string/next"
            android:src="@drawable/ic_media_next" />

        <ImageButton
            android:id="@+id/previous"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="false"
            android:layout_toLeftOf="@+id/startStop"
            android:contentDescription="@string/previous"
            android:src="@drawable/ic_media_previous" />

</RelativeLayout>

导致问题的代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >



<ImageView
    android:id="@+id/imageView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_centerInParent="true"
    android:contentDescription="@string/imageView"
    android:scaleType="centerInside"
    android:src="@drawable/image1" />

<TextView
    android:id="@+id/title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:background="#30eee9e9" >

            <ImageButton
        android:id="@+id/previous"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/previous"
        android:src="@drawable/ic_media_previous" />

    <ImageButton
        android:id="@+id/bla"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/startStop"
        android:src="@drawable/ic_menu_slideshow" />

    <ImageButton
        android:id="@+id/next"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/next"
        android:src="@drawable/ic_media_next" />

最佳答案

我遇到了同样的问题,但是将相对布局作为父布局,将线性布局作为子布局,我使用了四个图像按钮

  • 得分
  • 帮助
  • 退出

并且按钮功能被转移到下一个按钮,即当我按下 PLAY 时,当按下 SCORE 时没有任何反应 当点击 HELP 时游戏开始播放,显示我得分等等。 off dam thing 试图看电影,但有一段时间我厌倦了看电影,我再次启动了 Eclipse,它运行得非常好。不知道 但是 Rebuild & Clean 已经解决了我的问题,正如 DeeV 所说

关于android - 将按钮从相对布局更改为线性布局奇怪的副作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11832163/

相关文章:

java - Cucumber-jvm线程安全吗?

android - JSON 数据解析 - 如何?

android - 协调从org.opencv.core.Point到android.graphics.Point的转换

C#读取网站xml文件

java - 通过上下文对象的同步 getter 实现线程安全

带有 clang 的 C++ 11 线程

android - Firebase Crashlytics 何时将 Proguard/R8 映射文件上传到他们的服务器?

Android Intent ACTION.SEND——无法向 Twitter 或 Facebook 发送文本

android - 如何在android中将PreferenceScreen设置为其他布局

php - SimpleXML 更改文件编码