Android:ScrollView will not scroll at all - android

Here is my code, I have looked at and tried all of the solutions that other people were given and still it does not scroll? Nothing happens when I try to scroll though the ScrollView. I also tried replacing the ScrollView with 'android:scrollbars = "horizontal"'
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:background="#drawable/bgstardust"
android:orientation="vertical"
android:weightSum="2"
style="#style/AppTheme.NoActionBar"
tools:context="com.example.cs_gage.brickbreaker.BackgroundActivity">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1">
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:src="#drawable/button_outline_dark"
android:background="#drawable/bgblackdesign"
android:layout_margin="5dp" />
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:src="#drawable/button_outline_dark"
android:background="#drawable/bgdarksquares"
android:layout_margin="5dp" />
...
</LinearLayout>
</ScrollView>
</LinearLayout>

Related

Android FrameLayout Views Overlapping not Working

I Have the following layout and I need the favorite image to placed on the upper right corner of the itemImage using FrameLayout
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ItemDetails"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="20dp">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/itemdimage"
android:layout_width="match_parent"
android:layout_height="300dp"
android:scaleType="fitEnd"
tools:srcCompat="#mipmap/ic_launcher"
/>
<ImageView
android:id="#+id/favorite"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="end"
android:layout_margin="10dp"
tools:srcCompat="#mipmap/ic_launcher_round"
android:elevation="10dp"/>
</FrameLayout>
But the favorite image is never show ?? what is wrong with my layout
Any help will be much appreciated
Maybe this layout will work. I changed tools:srcCompat to android:src. tools: attributes are only visible in AndroidStudio, they are removed from the build.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="20dp">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/itemdimage"
android:layout_width="match_parent"
android:layout_height="300dp"
android:scaleType="fitEnd"
android:src="#mipmap/ic_launcher"/>
<ImageView
android:id="#+id/favorite"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="end"
android:layout_margin="10dp"
android:elevation="10dp"
android:src="#mipmap/ic_launcher_round" />
</FrameLayout>
</LinearLayout>
</ScrollView>
The result is this :

Static Button on Scroll View not Clickable Android

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#mipmap/bg"
android:scrollbars="none"
android:weightSum="1">
<Button
android:id="#+id/downbtn"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_gravity="bottom|center_horizontal"
android:layout_marginBottom="128dp"
android:layout_marginEnd="19dp"
android:background="#drawable/hand" />
<ScrollView
android:id="#+id/QuesSix"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true">
<LinearLayout
android:id="#+id/layoutSix"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp">
<com.badoualy.stepperindicator.StepperIndicator
android:id="#+id/stepper_indicator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:stpi_circleColor="#00b47c"
app:stpi_stepCount="6" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
I have implemented a static button on a scroll view. But the button (id: downbtn) is not clickable. Even if I add a onClick Listener, nothing happens. What can I do to make the button click and have a click event?
I tried all the blogs and nothing helped me.
In RelativeLayout you have to specify rules for child Views .
In your case Button hide behind the other view so it can not take click .
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#mipmap/bg"
>
<Button
android:id="#+id/downbtn"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="128dp"
android:layout_marginEnd="19dp"
android:background="#drawable/hand"
/>
<ScrollView
android:id="#+id/QuesSix"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/downbtn"
>
<LinearLayout
android:id="#+id/layoutSix"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp">
<com.badoualy.stepperindicator.StepperIndicator
android:id="#+id/stepper_indicator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:stpi_circleColor="#00b47c"
app:stpi_stepCount="6" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
Also android:weightSum is useless in case of RelativeLayout . You might wanna have look at Layouts in android

Android how to place a layout on top of two layouts

The layout should be align half on 1st layout bottom and half on second layouts top, i didn't got any clue on my searching. anyone help me!]1
This would work correct across all resolutions -
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="5">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="5dp"
android:layout_weight="3"
android:background="#000000" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="#000000" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="#000000" />
</LinearLayout>
<LinearLayout
android:layout_width="150dp"
android:layout_height="100dp"
android:layout_centerInParent="true"
android:background="#color/colorAccent" />
</RelativeLayout>
</LinearLayout>
So I went ahead and tried this out, and managed to do something like this..
Here is a simple code to help you:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="5">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="5dp"
android:layout_weight="3"
android:background="#000000" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="#000000" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="#000000" />
</LinearLayout>
<LinearLayout
android:layout_width="150dp"
android:layout_height="100dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="50dp"
android:background="#color/colorAccent" />
</RelativeLayout>
For more information regarding how to use a RelativeLayout, you can check the Official Android Developers Site - RelativeLayout.
Hope this helps.

Android - Layout SurfaceView and Image View

I am getting error when I tried to put image view on top of surface view.
Here is my XML code please help me in this regard
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#EFE3AF"
android:orientation="vertical" >
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="500dp"
android:layout_weight="1"
>
<SurfaceView
android:id="#+id/surfaceview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#null"
android:scaleType="fitXY"
/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:gravity="right"
android:orientation="vertical"
android:paddingRight="#dimen/right01"
android:paddingTop="#dimen/top02" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="#drawable/village" />
</LinearLayout>
</FrameLayout>
</LinearLayout>
</RelativeLayout>
Above code works fine if I will add surface view up and image down, but I want other way around.
Something like this?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#EFE3AF"
android:orientation="vertical">
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="500dp"
android:layout_weight="1">
<SurfaceView
android:id="#+id/surfaceview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#null"
/>
<ImageView
android:layout_gravity="top|right"
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FF0000" />
</FrameLayout>
</LinearLayout>
</RelativeLayout>

How to automatically set different item height in ExpandableListView?

I'm trying to use ExpandableListView with custom adapter in my project.
There is a result view of my activity with ExpandableListView:
How you can see, some rows doesn't have a right height and some lines are cropped.
What i do wrong?
There are my layout files
activity layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ExpandableListView
android:layout_width="matc_parent"
android:layout_height="match_parent"
android:id="#+id/noticeList"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="#+id/empty"
android:text="#string/empty"/>
</LinearLayout>
and layout for item of ExpandableListView:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:id="#+id/noticeImage"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="20dp"
android:id="#+id/noticeDate"/>
<TextView
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="#+id/noticeTitle"/>
</LinearLayout>
</LinearLayout>
Thanks all for answers.
The solution is use RelativeLayout instead LinearLayout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:id="#+id/noticeImage"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/noticeImage"
android:id="#+id/noticeDate"
/>
<TextView
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="#+id/noticeTitle"
android:layout_toRightOf="#+id/noticeImage"
android:layout_below="#+id/noticeDate"
/>
</RelativeLayout>
Try to set layout_height for TextView noticeDate to wrap_content
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:id="#+id/noticeImage"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/noticeDate"/>
<TextView
android:layout_height="match_parent"
android:layout_width="fill_parent"
android:id="#+id/noticeTitle"/>
</LinearLayout>
</LinearLayout>

Categories

Resources