Android scrollable layout - views not visible on orientation change - java

My XML scrollable layout (work in progress) looks like this:
<?xml version="1.0" encoding="utf-8"?>
<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:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ListView
android:id="#+id/list"
android:layout_height="wrap_content"
android:layout_width="match_parent"
>
</ListView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="#+id/tvStatus"
android:text="0 SMS found"
android:textSize="15sp"
android:layout_width="120dp"
android:layout_height="wrap_content" />
<Button
android:id="#+id/btnExport"
android:layout_width="88dp"
android:layout_height="wrap_content"
android:text="Export"
/>
</LinearLayout>
</LinearLayout>
</ScrollView>
When load app on testing device in portrait mode, all views are presented and visible:
portrait mode
When device orientation is changed to horizontal, only listview part of layout is visible (?!?):
landscape mode
Does anybody has clue on what possibly is going on here? Thanks.

This is the layout you need:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
</ListView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/tvStatus"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:text="0 SMS found"
android:textSize="15sp"/>
<Button
android:id="#+id/btnExport"
android:layout_width="88dp"
android:layout_height="wrap_content"
android:text="Export"
/>
</LinearLayout>
</LinearLayout>
You can also view how will your layout be in landscape mode while constructing it:

it seems you are missing closing tag of scroll view.

Related

My scrollview in a linear layout is pushing up other widgets above it

So my button and edit text widgets keep getting pushed upwards when I dynamically add text views to my scroll view. So the scrollview's height is also being bumped up. How do I just make sure the scroll view is fixed, I've looked at similar questions and tried implementing it but not working.
<?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:windowSoftInputMode="stateVisible|adjustPan"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<EditText
android:id="#+id/name"
android:hint="Enter name"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.25"/>
<EditText
android:id="#+id/phone_num"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.25"
android:hint="Enter Phone Number"/>
<Button
android:id="#+id/submit"
android:layout_width="150dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:text="#string/submit_contact"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:isScrollContainer="false"
android:fillViewport="true">
<LinearLayout
android:id="#+id/layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
</ScrollView>
</LinearLayout>
Try to set all heights to 0dp and give the wheightSum to the parent view. To have a fixed height of the button surround it with a LinearLayout.
<?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:windowSoftInputMode="stateVisible|adjustPan"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="2.75"
android:orientation="vertical"
tools:context=".MainActivity">
<EditText
android:id="#+id/name"
android:hint="Enter name"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.25"/>
<EditText
android:id="#+id/phone_num"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.25"
android:hint="Enter Phone Number"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.25"
android:orientation="vertical">
<Button
android:id="#+id/submit"
android:layout_width="150dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:text="test"/>
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:isScrollContainer="false"
android:fillViewport="true">
<LinearLayout
android:id="#+id/layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
</ScrollView>
</LinearLayout>
Try it out, If it dont work you may post what you have tried alredy and the code how you ad the textViews dynamicly. Good luck

Floating Action Button and CardView

How to add Floating Action Button from the support library for CardView so that when you scroll through the ScrollView, the button has gone up along with the card?
My app
before scrolling
after scrolling
The button should go along with the card
I want to fix this
Layout
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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:fitsSystemWindows="true"
>
<ScrollView
android:id="#+id/nested_scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white_vk_background_color">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/spacing_8"
android:orientation="vertical"
android:padding="#dimen/spacing_16">
<android.support.v7.widget.CardView
android:id="#+id/behavior_card_view"
style="#style/RateCardView"
app:cardBackgroundColor="#color/white"
app:cardCornerRadius="#dimen/spacing_2"
app:cardElevation="#dimen/spacing_8">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="#dimen/spacing_16"
android:orientation="vertical"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingBottom="#dimen/spacing_8">
<TextView
android:id="#+id/description_rate_usd_text_view"
style="#style/AppTextView.RateTextView"
android:text="#string/description_currency_text_view_usd"/>
<TextView
android:id="#+id/rate_usd_text_view"
style="#style/AppTextView.RateTextView"
android:layout_centerHorizontal="true"
android:layout_toRightOf="#id/description_rate_usd_text_view"
tools:text="63.99"
/>
<TextView
android:id="#+id/rate_difference_usd_text_view"
style="#style/AppTextView.DifferenceTextView"
android:layout_toRightOf="#id/rate_usd_text_view"
tools:text="+0.44"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingBottom="#dimen/spacing_8">
<TextView
android:id="#+id/description_rate_eur_text_view"
style="#style/AppTextView.RateTextView"
android:text="#string/description_currency_text_view_eur"/>
<TextView
android:id="#+id/rate_eur_text_view"
style="#style/AppTextView.RateTextView"
android:layout_centerHorizontal="true"
android:layout_toRightOf="#id/description_rate_eur_text_view"
tools:text="71.99"
/>
<TextView
android:id="#+id/rate_difference_eur_text_view"
style="#style/AppTextView.DifferenceTextView"
android:layout_toRightOf="#id/rate_eur_text_view"
tools:text="+0.15"/>
</RelativeLayout>
<TextView
android:id="#+id/rate_update_time_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|start"
android:layout_marginBottom="#dimen/spacing_8"
android:layout_marginLeft="#dimen/spacing_16"
android:layout_marginTop="#dimen/spacing_16"
android:gravity="center"
android:textSize="#dimen/density_font_size_text_date"
tools:text="Date: 15.07.2016"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/converter_card_view"
style="#style/RateCardView"
app:cardBackgroundColor="#color/white"
app:cardCornerRadius="#dimen/spacing_2"
app:cardElevation="#dimen/spacing_8">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="#dimen/spacing_16">
<com.rengwuxian.materialedittext.MaterialEditText
android:id="#+id/converter_ruble_edit_text"
style="#style/RateEditText"
android:hint="#string/description_currency_ruble"
app:met_baseColor="#android:color/black"
app:met_bottomTextSize="#dimen/density_font_size_text_converter"
app:met_errorColor="#color/red_light"
app:met_floatingLabel="normal"
app:met_floatingLabelAlwaysShown="true"
app:met_floatingLabelTextSize="#dimen/density_font_size_text_converter"
app:met_helperText=""
app:met_primaryColor="#color/red_light"
app:met_textColorHint="#android:color/transparent"/>
<com.rengwuxian.materialedittext.MaterialEditText
android:id="#+id/converter_dollar_edit_text"
style="#style/RateEditText"
android:hint="#string/description_currency_dollar"
app:met_baseColor="#android:color/black"
app:met_bottomTextSize="#dimen/density_font_size_text_converter"
app:met_errorColor="#color/red_light"
app:met_floatingLabel="normal"
app:met_floatingLabelAlwaysShown="true"
app:met_floatingLabelTextSize="#dimen/density_font_size_text_converter"
app:met_helperText=""
app:met_primaryColor="#color/red_light"
app:met_textColorHint="#android:color/transparent"/>
<com.rengwuxian.materialedittext.MaterialEditText
android:id="#+id/converter_euro_edit_text"
style="#style/RateEditText"
android:hint="#string/description_currency_euro"
app:met_baseColor="#android:color/black"
app:met_bottomTextSize="#dimen/density_font_size_text_converter"
app:met_errorColor="#color/red_light"
app:met_floatingLabel="normal"
app:met_floatingLabelAlwaysShown="true"
app:met_floatingLabelTextSize="#dimen/density_font_size_text_converter"
app:met_helperText=""
app:met_primaryColor="#color/red_light"
app:met_textColorHint="#android:color/transparent"/>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</ScrollView>
<android.support.design.widget.FloatingActionButton
android:id="#+id/update_floating_action_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/density_spacing_size_floating_action_button"
android:layout_marginRight="#dimen/float_action_button_spacing_8"
android:src="#drawable/ic_cached_white_24dp"
app:fabSize="mini"
app:layout_anchor="#id/behavior_card_view"
app:pressedTranslationZ="6dp"
app:layout_anchorGravity="end|right|center"
/>
</android.support.design.widget.CoordinatorLayout>
Instead of anchoring to behavior_card_view, try anchoring it to something inside behavior_card_view. Ideally, anchor to the bottom of the USD textview. This should prevent the FAB from sliding down.
I would actually create a invisible layout which I can use to anchor but it doesn't affect the UI otherwise.
I can't replicate the issue you are having but the following works as you want:
<RelativeLayout
android:id="#+id/rl1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="10dp"
android:paddingRight="10dp">
<TextView
android:id="#+id/tv1"
android:layout_width="match_parent"
android:layout_height="100dp"
android:paddingLeft="12dp"
android:text="Setting"
android:focusable="true"
android:focusableInTouchMode="true" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:src="#drawable/ic_add"
app:fabSize="mini"
app:pressedTranslationZ="6dp"
app:layout_anchorGravity="end|right|center"
app:layout_anchor="#id/tv1" />
... a lot of elements here ...
</RelativeLayout>
This RelativeLayout is the only element inside my ScrollView element.

LinearLayout Buttons not appearing when device orientation changed to Horizontal?

Here is the xml in which ScrollView layout size will vary means it will zoom image on button click but my top headers and footer will always be in same position irrespective of zoom values.......
XML
<?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">
<LinearLayout
android:id="#+id/layout_zoom_buttons"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/btn_zoomIn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/zoomin1" />
<ImageView
android:id="#+id/btn_zoomout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/zoomin1" />
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<com.example.imagetouchview.TouchImageView
android:id="#+id/imagezoom"
android:layout_width="fill_parent"
android:layout_height="400dp"
android:layout_gravity="center">
</com.example.imagetouchview.TouchImageView>
</ScrollView>
<LinearLayout
android:id="#+id/layout_buttons"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="#+id/btn_email_fatwa"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/zoomin1"
android:layout_weight="1"/>
<ImageView
android:id="#+id/btn_share_fatwa"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/zoomin1"
android:layout_weight="1"/>
<ImageView
android:id="#+id/btn_save_fatwa"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/zoomin1"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
this layout is fine in vertical orientation while when device orientatio changes to Horizontal the bottom buttons are invisible.I am following Salmans Ayub Answer For Image Zoomin and Out
I think You have design your layout in portrait mode(verticaly). Now either you have to bound it for
portrait mode by adding this line android:screenOrientation="portrait" in your activity manifest,
OR
You have to design it for landscape mode by following this link-
Android: alternate layout xml for landscape mode

LinearLayout and TextView doesn't show properly

I'm trying to create a new LinearLayout and now i have added a text and a background and now the background appears and still not full as it seems in the graphical they both show up in the graphical layout
example here:
https://www.dropbox.com/s/k58uznho9pu5qky/Untitled1.png
and when i test it out in a emulator which is real device the background isn't showing probably with some white space down and the text doesn't even appear
example here:
https://www.dropbox.com/s/q9e45sunbsesrd1/uniteled3.png
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/relLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="right"
android:orientation="vertical"
tools:context=".SecondActivity" >
<LinearLayout
android:id="#+id/linearlayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/images"
android:gravity="center|right"
android:orientation="vertical" >
<TextView
android:id="#+id/two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingTop="10sp"
android:text="testing ytestifnfndfijdfhffdkjdfkjfdjkj"
android:textSize="25sp" />
</LinearLayout>
</ScrollView>
How does this fit your needs? If you plan to add more content, then the root component can be ScrollView with the background. But with only one TextView, there should be no need for ScrollView unless the text is huge.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
xmlns:tools="http://schemas.android.com/tools"
android:background="#drawable/images"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".SecondActivity" >
<TextView
android:id="#+id/two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="testing ytestifnfndfijdfhffdkjdfkjfdjkj"
android:textSize="25sp" />
</LinearLayout >
to fill whole screen with your layout use match_parent for layout_height and layout_width
<LinearLayout
android:id="#+id/linearlayout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/images"
android:gravity="center|right"
android:orientation="vertical" >

Unable to make all UI components appear in RelativeLayout

I want a RelativeLayout based android UI that looks like the below mock graphic:
Below is my layout xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayoutForPreview"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- surface view that contains camera preview , and seats above #+id/linearLayoutToolbar -->
<SurfaceView
android:id="#+id/surfaceViewBarcodeScanner"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<!-- LinearLayout that contains toolbar that is divided into 3 sections horizontally -->
<LinearLayout
android:id="#+id/linearLayoutToolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/surfaceViewBarcodeScanner"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/scanner_bottom_left" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/scanner_bottom_center_toolbar" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/scanner_bottom_right_landscape_button" />
</LinearLayout>
</RelativeLayout>
I used Eclipse GUI palette and my own editing , however the output was not what I expected, the SurfaceView seems to covering all the screen, the LinearLayout at the bottom does not appear.
Snapshot of my current result on Galaxy S3 device:
Any help will be appreciated, Thanks.
Could you please try out to modify your layout as the follows:
Define your SurfaceView and set it's layout_above value to the ID of the linear layout made in the previous step. Set the layout_alignParentTop to true.
Define your bottom linear layout and set the layout_alignParentBottom to true.
Smart code snippet with only the important parts:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android">
<SurfaceView
android:id="#+id/surfaceViewBarcodeScanner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_above="#+id/linearLayoutToolbar" />
<LinearLayout
android:id="#+id/linearLayoutToolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
</RelativeLayout>
I hope this will solve your problem.
you can use Linearlayout instead of Realtive Layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<SurfaceView
android:id="#+id/surfaceViewBarcodeScanner"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" />
<LinearLayout
android:id="#+id/linearLayoutToolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<!-- inside elements -->
</LinearLayout>
</LinearLayout>
else you should use android:layout_above="#+id/linearLayoutToolbar" to your surfaceview
and remove android:layout_below attribute and add android:layout_alignParentBottom="true" to your toolbar view.
// try this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LinearLayoutForPreview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp"
android:orientation="vertical">
<LinearLayout
android:layout_height="0dp"
android:layout_weight="1"
android:layout_width="match_parent">
<SurfaceView
android:id="#+id/surfaceViewBarcodeScanner"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayoutToolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="0dp"
android:gravity="center"
android:layout_weight="1">
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/scanner_bottom_left" />
</LinearLayout>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="0dp"
android:gravity="center"
android:layout_weight="2">
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/scanner_bottom_center_toolbar" />
</LinearLayout>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="0dp"
android:gravity="center"
android:layout_weight="1">
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/scanner_bottom_right_landscape_button" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

Categories

Resources