当前位置: 首页 > 知识库问答 >
问题:

图像顶部的Android按钮不起作用

羿易安
2023-03-14

布局是:在视图显示图像的顶部和图像的顶部,在右上角的显示位置-持久按钮中(同时向下滚动图像下面的文本-位置是固定的)。它不起作用:按钮隐藏在图像下面,只有当我向下滚动到文本的白色背景时,我才能看到按钮。这是代码。该按钮是自定义的形状:椭圆形彩色与图像作为背景。我还尝试将android:background=“@drawable/btn1_shape”更改为android:src=“@drawable/btn1_shape”,但也不起作用。我说的是matheirial前主题设计(用它的Z值等),因为我需要支持向后兼容性...

<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"
    tools:context="com.example.MainActivity" >

    <Button
        android:id="@+id/btn1"
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_marginTop="30dp"
        android:layout_marginRight="20dp"
        android:layout_marginEnd="20dp"
        android:background="@drawable/btn1_shape" />

    <ScrollView 
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <ImageView
                android:id="@+id/image1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:adjustViewBounds="true"
                android:src="@drawable/picture1" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

        </LinearLayout>

    </ScrollView>

</RelativeLayout>

//Button shape xml: @drawable/btn1_shape
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="oval">
            <solid android:color="@color/primary"/>
        </shape>
    </item>
    <item android:drawable="@drawable/picture2"/>
</layer-list>

共有1个答案

慕烨烁
2023-03-14

据我所知,你的问题是通过,

<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"
tools:context="com.example.MainActivity" >


<ScrollView 
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <ImageView
            android:id="@+id/image1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:adjustViewBounds="true"
            android:src="@drawable/picture1" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    </LinearLayout>

</ScrollView>
<Button
    android:id="@+id/btn1"
    android:layout_width="60dp"
    android:layout_height="60dp"
    android:layout_alignParentTop="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:layout_marginTop="30dp"
    android:layout_marginRight="20dp"
    android:layout_marginEnd="20dp"
    android:background="@drawable/btn1_shape" />
</RelativeLayout>
 类似资料:
  • 我有两个pngs。一个是在IOS上下载应用程序,另一个是在google play上获取它。 现在的问题是,我想把这些图像转换成按钮。因此,当它们被按下时,相应的按钮将用户重定向到app store和play store。

  • 我能找到的每个更改按钮图像的示例都显示了当单击该按钮时如何更改它。但是我如何点击一个切换按钮,并让它改变一个常规按钮的图像呢? 关于更多细节,我有两个按钮和一个onCheckedChanged事件: 当按下切换按钮并发生onCheckedChanged事件时,我需要将btn1的背景设置为新图像。

  • 我刚刚在文件夹下添加了一个新的可绘制文件夹。在drawable文件夹中,我复制了ic\U启动器。png文件来自可绘制hdpi文件夹。当我按下按钮时,我想通过新的图像更改标准的图像按钮。我写了一些代码,但当我启动应用程序时,它崩溃了。 编辑:我改成了这个,这个也不行。 编辑2:这很有效。感谢大家。

  • 我在使用Android GridView时遇到了奇怪的问题。我创建了一个3x4的网格,并在其中插入了按钮。我希望当用户单击按钮时,按钮的背景发生变化。这对于除了第一个按钮(索引为0 -左上角的那个)之外的所有按钮都很好。无论我做什么,OnClick事件侦听器都不会为那个按钮触发。 这是我创建视图的代码: 如果我换掉 具有 然后onClick()被触发,但背景仍然没有改变。所有其他按钮都按预期工作。

  • 问题内容: Left 为什么“主数据”在上面的代码中不起作用? 问题答案: 您可以将两个浮动div放入 另一个 设置为“溢出:隐藏”的div中: 编辑 —为这个已有5年历史的答案添加一点点:我认为造成混乱的原因是_利润率下降的_ 过程有些复杂。使用OP中原始HTML的一个好技巧是添加一个CSS规则,如下所示: of!现在(没有我的额外要求)可以正常工作!好吧,除了边界上的多余像素。特别是,我 认为