I am working on a app where the user actions add LinearLayout's to the pre-existing LinearLayout #+id/linLayout. Sometimes these additional layouts will go off the bottom of the screen so I have put the main LinearLayout within a ScrollView. When my app starts to go off the bottom of the screen it is able to scroll a little bit but not far enough to see everything. At a certain point it is not possible to continue because a Button is off screen and cannot be pressed. Can anybody tell me what I'm doing wrong?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="#dimen/activity_horizontal_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:showIn="#layout/activity_main"
tools:context=".MainActivity">
<LinearLayout 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:orientation="vertical" >
<Button android:id="#+id/bGenerateExample"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/generate_example" />
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/linLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
</LinearLayout>
</RelativeLayout>
What about using weight_Sum?
<LinearLayout 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:orientation="vertical"
android_weight_sum=5 >
<Button android:id="#+id/bGenerateExample"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="#string/generate_example" />
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="4">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/linLayout"
android:layout_width="match_parent"
android:layout_height="marth_parent"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
</LinearLayout>
now button covers %20 percent of screen and scrollView covers %80.You can change it easily with changing layout_weight values of scrollView, Button.
Related
I have an activity with a title, a fragment with a recyclerview full of cards and a bottom navigaton bar.
I cannot manage to show all 3 together without problems, the closest I have been is showing all 3, but with the bar taking space from the cards space.
Right now this is the XML which I thought should be working:
<LinearLayout 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"
tools:context=".habits.HabitsActivity">
<ImageView
android:id="#+id/imageView"
android:layout_width="313dp"
android:layout_height="166dp"
android:layout_gravity="center_horizontal"
app:srcCompat="#drawable/goodreasons" />
<android.support.design.widget.CoordinatorLayout
android:id="#+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/contentFrame"
android:layout_width="match_parent"
android:layout_height="match_parent"></FrameLayout>
</android.support.design.widget.CoordinatorLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom">
<com.aurelhubert.ahbottomnavigation.AHBottomNavigation
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom" />
</FrameLayout>
</LinearLayout>
But this gives this output:
This is the xml of the fragment, in case you think it is relevant too.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:layout_gravity="center"
android:orientation="vertical"
android:padding="5dp"
>
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_list"
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
android:layout_gravity="center"
/>
</LinearLayout>
Here's your layout, stripped down:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:layout_width="313dp"
android:layout_height="166dp"/>
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
Your problem is that the CoordinatorLayout has a match_parent height, so it will take up all of the space that the ImageView doesn't. That leaves no space at all for the FrameLayout, so you won't be able to see anything inside of it.
Probably the best thing to do would be to use layout_weight on the CoordinatorLayout to make it take up as much space as it can while still leaving room for other views. That would look something like this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:layout_width="313dp"
android:layout_height="166dp"/>
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
The only changes I made were to set the CoordinatorLayout's height to 0dp and the FrameLayout's height to wrap_content, and to add the weight attribute to the CoordinatorLayout.
This is resizing when the keyboard is showing instead of scrolling. Why is that?
I have adjustResize set in the Manifest but it still isnt scrolling. What else do I need to change? I have tried removing isScrollableView also.
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/night"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_horizontal"
android:isScrollContainer="true">
<ImageView
android:id="#+id/iv_login_logo"
android:layout_width="#dimen/login_logo_width"
android:layout_height="#dimen/login_logo_height"
android:src="#drawable/travelbank_logo_white"
android:layout_marginTop="#dimen/login_logo_margin"
android:layout_marginBottom="#dimen/login_logo_margin"/>
<!--Tab Layout-->
<android.support.design.widget.TabLayout
android:id="#+id/tl_login_tabs"
android:layout_width="match_parent"
android:layout_height="#dimen/tab_layout_height"
app:tabGravity="fill"
tabMode="fixed"
app:tabTextAppearance="#style/NavigationTabTextAppeareance"
app:tabIndicatorHeight="0dp"
app:tabPadding="0dp"/>
<!--Login Page-->
<android.support.v4.view.ViewPager
android:id="#+id/vp_login_view_pager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
</LinearLayout>
</ScrollView>
Turns out you cant have a View Pager inside a Scroll View. I removed the View Pager and everything works fine
I have a horizontalScrollView containing 1 image that is used as the background. This image can be scrolled left to right. I would like to place other imageviews on to the background image but not have them scroll with it. At the moment if I place another imageview on top of this, when I scroll the image comes as well.
The scroll view at far left:
The scroll view at far right:
XML Code:
<?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:id="#+id/activity_rear_gunner"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:focusable="true"
tools:context="com.example.mr_br.ibcc_bomber_command.rear_gunner">
<HorizontalScrollView
android:id="#+id/horizontalScrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:layout_alignParentTop="true"
>
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent" app:srcCompat="#drawable/background_scroll_2"
android:id="#+id/scrollView" android:layout_centerVertical="true"
android:scaleType="centerCrop"
/>
</HorizontalScrollView>
<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:id="#+id/item_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:focusable="true"
tools:context="com.example.mr_br.ibcc_bomber_command.rear_gunner">
</RelativeLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content" app:srcCompat="#drawable/placeholder_bomber"
android:id="#+id/enemy" android:layout_centerVertical="true"
/>
</RelativeLayout>
Very new to using layouts in android. Hope I made my problem clear if not I do apologize and will try to clarify if asked. I know this could have something to do with what layouts I am using and the child and parents of them layouts but like I said new to this.
The HorizontalSCrollView can have only one child, but that child could be another layout, so you can add as many ImageView you want.
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
>
<ImageView
android:layout_width="3000dp"
android:layout_height="match_parent"
android:background="#a30"
/>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:background="#aa0"
/>
</RelativeLayout>
</HorizontalScrollView>
When i applied an image to emulator on android studio, it gives an image without covering borders. Screen shot of this problem is as under, but what i get is to completely fill the emulator with my image.
XML code:
<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="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:background="#drawable/background_image"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".MainActivity">
</RelativeLayout>
Your XML looks like :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
android:paddingBottom="16dp"" >
So the thing you've to do is remove the paddings from your XML, and if you have put the image correctly it will fit on your screen :)
EDIT1
<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:background="#drawable/background_image"
tools:context=".MainActivity">
</RelativeLayout>
EDIT2
<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:background="#drawable/background_image"
android:layout_centerInParent="true"
android:scaleType="centerCrop"
tools:context=".MainActivity">
</RelativeLayout>
EDIT3
Use this image instead : http://i.imgur.com/oqES1TU.jpg
I'm having an issue with a ListView and a ScrollView and adding a drop shadow between the listview and the ScrollView.
I had made a shape, which works great with a ListView and a relative layout, but does not work with the ScrollView.
I have done the following - Dashboard List
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="8dp"
android:paddingRight="8dp">
<ListView
android:id="#id/android:list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:choiceMode = "singleChoice"
android:listSelector="#31ABD4"
android:drawSelectorOnTop="false"/>
<TextView android:id="#id/android:empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="No data"/>
</RelativeLayout>
Dashboard with scroll view
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/white" >
<View
android:layout_width="10dp"
android:layout_height="fill_parent"
android:background="#drawable/shadow_left" />
</RelativeLayout>
</ScrollView>
View
<?xml version ="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:angle="180"
android:width="10dp"
android:centerX="0.1"
android:gravity="right"
android:startColor="#00000000"
android:endColor="#55000000"
android:type = "linear"
/>
</shape>
Edit - Attached Screenshots
Thank you all,
James
seems that you are missing the paddings on "Dashboard with scroll view"
try this instead
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="8dp"
android:paddingRight="8dp" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/white" >
<View
android:layout_width="10dp"
android:layout_height="fill_parent"
android:background="#drawable/shadow_left" />
</RelativeLayout>
</ScrollView>