【问题标题】:Android Crash when ImageButton Src Added添加 ImageButton Src 时 Android 崩溃
【发布时间】:2015-06-25 15:54:14
【问题描述】:

我认为我有 3 个ImageButtons。其中一个在src 中有一个drawable,它可以工作。当我将src 添加到另外两个时,当我点击最初具有图像的同一个按钮时,应用程序崩溃了。

下面是代码:

<RelativeLayout 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" android:paddingLeft="0px"
android:paddingRight="0px"
android:paddingTop="0px"
android:paddingBottom="0px" tools:context=".MainActivity">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="400px"
    android:id="@+id/relativeLayout">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Large Text"
        android:id="@+id/textView" />


</RelativeLayout>


<View
    android:layout_width="match_parent"
    android:layout_height="500px"
    android:background="#2196F3"
    android:id="@+id/topRowBackground"/>

<ImageButton
    android:layout_width="80px"
    android:layout_height="80px"
    android:layout_marginLeft="20px"
    android:layout_marginTop="20px"
    android:id="@+id/logOut"
    android:background="@android:color/transparent"
    android:shadowColor="@android:color/transparent"
    android:layout_weight="1"
    android:src="@drawable/log_out"
    android:scaleType="fitStart"/>

<ImageView
    android:layout_width="100px"
    android:layout_height="100px"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="100px"
    android:background="@android:color/transparent"
    android:shadowColor="@android:color/transparent"
    android:layout_weight="1"
    android:src="@drawable/user_icon"
    android:scaleType="fitStart"/>

<TextView
    android:text="[username]"
    android:id="@+id/username"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:textColor="#1b1b1b"
    android:textSize="60px"
    android:layout_marginTop="240px"/>

<TextView
    android:text="Points: [points]"
    android:id="@+id/points"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:textColor="#1b1b1b"
    android:textSize="60px"
    android:layout_marginTop="350px"/>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/topRowBackground"
    android:weightSum="3"
    android:orientation="vertical"
    android:background="#1b1b1b">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:weightSum="2"
        android:paddingTop="5dp"
        android:paddingBottom="5dp"
        android:orientation="vertical"
        android:background="#ff1b1b1b"
        android:id="@+id/challengeLayout">


        <ImageButton
            android:layout_width="100dp"
            android:layout_height="0dp"
            android:layout_centerVertical="true"
            android:id="@+id/challengeIcon"
            android:background="@android:color/transparent"
            android:shadowColor="@android:color/transparent"
            android:layout_weight="1"
            android:src="@drawable/challenge_icon"
            android:layout_gravity="center|bottom"
            android:padding="10dp"
            android:scaleType="fitCenter"/>


        <Button
            android:id="@+id/challengeButton"
            android:layout_width="match_parent"
            android:text="Challenge"
            android:background="#1B1B1B"
            android:shadowColor="@android:color/transparent"
            android:textColor="#2196F3"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:textSize="18dp"
            android:scaleType="fitCenter"
            android:gravity="center_horizontal|top"/>


    </LinearLayout>



    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:weightSum="2"
        android:paddingTop="5dp"
        android:paddingBottom="5dp"
        android:orientation="vertical"
        android:background="#1B1B1B"
        android:id="@+id/leaderboardLayout">

        <ImageView
            android:id="@+id/leaderboardIcon"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:scaleType="fitCenter"
            android:layout_gravity="center|bottom"
            android:padding="10dp"
            android:background="@android:color/transparent"
            android:shadowColor="@android:color/transparent"
            android:layout_margin="12px"
            android:src="@drawable/leaderboard_icon"/>


        <Button
            android:id="@+id/leaderboardButton"
            android:layout_width="match_parent"
            android:text="Leaderboard"
            android:background="#1B1B1B"
            android:shadowColor="@android:color/transparent"
            android:textColor="#2196F3"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:textSize="18dp"
            android:scaleType="fitCenter"
            android:gravity="center_horizontal|top"/>





    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:weightSum="2"
        android:paddingTop="5dp"
        android:paddingBottom="5dp"
        android:orientation="vertical"
        android:background="#1B1B1B"
        android:id="@+id/storeLayout">

        <ImageButton
            android:id="@+id/storeIcon"
            android:layout_width="100dp"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:scaleType="fitCenter"
            android:layout_gravity="center|bottom"
            android:padding="10dp"
            android:background="@android:color/transparent"
            android:shadowColor="@android:color/transparent"
            android:src="@drawable/store_icon"
            />

        <Button
            android:id="@+id/storeButton"
            android:layout_width="match_parent"
            android:text="Store"
            android:background="#1B1B1B"
            android:shadowColor="@android:color/transparent"
            android:textColor="#2196F3"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:textSize="18dp"
            android:scaleType="fitCenter"
            android:gravity="center_horizontal|top"/>
    </LinearLayout>

</LinearLayout>

</RelativeLayout>

【问题讨论】:

  • 你能分享堆栈跟踪吗?
  • 另外请说明您收到此错误的按钮
  • 发布活动并记录

标签: android image imagebutton android-drawable android-imagebutton


【解决方案1】:

问题似乎是我的图像文件太大。一旦我减小了它们的大小,应用就开始按预期运行。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-26
    • 1970-01-01
    • 2020-10-01
    • 2016-10-03
    相关资源
    最近更新 更多