【问题标题】:Android button on top of image not working图像顶部的Android按钮不起作用
【发布时间】:2015-05-16 08:18:45
【问题描述】:

布局是:在视图显示图像的顶部和图像的顶部,在右上角显示位置-永久按钮(同时向下滚动查看图像下方的文本-位置是固定的)。它不起作用:按钮隐藏在图像下方,只有当我向下滚动到文本的白色背景时,我才能看到按钮。这是代码。该按钮是自定义形状:椭圆形,以图像为背景。我还尝试将 android:background="@drawable/btn1_shape" 更改为 android:src="@drawable/btn1_shape" 并且它也不起作用。我说的是 pre 数学主题设计(带有 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>

【问题讨论】:

    标签: android button layout imageview scrollview


    【解决方案1】:

    据我所知,你的问题已经解决了,

    <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>
    

    【讨论】:

      【解决方案2】:

      如果您希望按钮显示在顶部,我相信您应该在声明滚动视图后声明该按钮。所以只需改变按钮和滚动视图之间的位置。如果我没错的话。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-01-19
        • 1970-01-01
        • 1970-01-01
        • 2011-03-18
        • 2011-11-12
        • 1970-01-01
        • 1970-01-01
        • 2016-07-04
        相关资源
        最近更新 更多