Reputation: 3945
The layout is: On top of the view display image and on top of the image, in the top-right corner display position-persistent button (while scrolling down for the text below the image-the position is fixed). It's not working: The button hides under the image, and only when I scroll down to the white background of the text, I can see the button. Here is the code. The button is custom shape: Oval colored with image as background. I also tried to change android:background="@drawable/btn1_shape" to android:src="@drawable/btn1_shape" and it's not worked either. I'm talking about pre matheirial theme design (with it`s Z value etc.) because I need to support backward compatibility...
<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>
Upvotes: 0
Views: 192
Reputation: 657
what i understand , your problem is solved by,
<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>
Upvotes: 2
Reputation: 68
I believe you should declare the button after you declare your scrollview if you'd like the button to appear on top. So just change places between the button and the scrollview. If I'm not mistaken.
Upvotes: 1