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
Related
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.
Why is the scrollview going behind the button here? I want the scrollview to stretch in height depending on the device but cant get it to work as it always goes behind the button.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/detail_view"
style="#style/DetailView">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical" >
<TextView
style="#style/TextView"
android:id="#+id/textview_message_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center">
</TextView>
<TextView
style="#style/TextView"
android:id="#+id/textview_message_date"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center">
</TextView>
<ScrollView
android:id="#+id/scrollview_message_text"
android:layout_height="wrap_content"
android:paddingBottom="20dip"
android:layout_width="fill_parent">
<TextView
style="#style/TextView"
android:id="#+id/textview_message_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</TextView>
</ScrollView>
</LinearLayout>
<LinearLayout style="#style/DetailView.Buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
style="#style/Button"
android:layout_marginTop="5dip"
android:id="#+id/button_view_file"
android:text="#string/viewfile"/>
</LinearLayout>
</RelativeLayout>
Here is a working copy of what I think you are looking for
1: Moved the buttons to the top of the relative layout ( added an id )
android:layout_alignParentBottom="true"
<LinearLayout android:id="#+id/buttons"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginTop="5dip"
android:id="#+id/button_view_file"
android:text="Button"/>
</LinearLayout>
2: Add in the layout containing the scroll change the width and height to match parent
but ( CRITICAL ) add android:layout_above="#id/buttons"
<LinearLayout
android:layout_above="#id/buttons"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/darker_gray"
android:gravity="center"
android:orientation="vertical" >
So putting it all together:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="#+id/detail_view"
>
<!-- Buttons at the top of layout but aligned to the bottom -->
<LinearLayout android:id="#+id/buttons"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginTop="5dip"
android:id="#+id/button_view_file"
android:text="Button"/>
</LinearLayout>
<!-- Linear layout to fill screen, but assigned to layout above the buttons -->
<LinearLayout
android:layout_above="#id/buttons"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/darker_gray"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="#+id/textview_message_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center">
</TextView>
<TextView
android:id="#+id/textview_message_date"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center">
</TextView>
<ScrollView
android:id="#+id/scrollview_message_text"
android:layout_height="wrap_content"
android:paddingBottom="20dip"
android:layout_width="fill_parent">
<TextView
android:id="#+id/textview_message_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</TextView>
</ScrollView>
</LinearLayout>
</RelativeLayout>
I removed the styles so I could see it in the layout an make sure this worked before posting. Hope this helps.
Relative layout allows you to layer elements on top of each other. So if that is not what you are looking for you need to make use of the toLeft, toRight, above, below directives to nudge the layouts into the correct position.
This happens because you use Relative layout as the root layout. So both layout are placed on the same place but the button layout is declared after the scrollview so it is shown above the scrollview
The opposite would happen if you were defining the button before the scrollview
So you should define it as shown below to achieve what you want.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/detail_view"
style="#style/DetailView">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_above="#id/layout_bottom"
android:orientation="vertical" >
<TextView
style="#style/TextView"
android:id="#+id/textview_message_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center">
</TextView>
<TextView
style="#style/TextView"
android:id="#+id/textview_message_date"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center">
</TextView>
<ScrollView
android:id="#+id/scrollview_message_text"
android:layout_height="wrap_content"
android:paddingBottom="20dip"
android:layout_width="fill_parent">
<TextView
style="#style/TextView"
android:id="#+id/textview_message_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</TextView>
</ScrollView>
</LinearLayout>
<LinearLayout
android:id="#+id/layout_bottom"
style="#style/DetailView.Buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
style="#style/Button"
android:layout_marginTop="5dip"
android:id="#+id/button_view_file"
android:text="#string/viewfile"/>
</LinearLayout>
</RelativeLayout>
or you can try and use LinearLayout as the root view and set
layout_height = "0dp"
layout_weight = "1"
to the layout containing the scrollview
using both these way will make the button stick to the bottom of the layout and the top layout will get all the remaining height.
Good Luck
Why is the scrollview going behind the button here?
Because it is coming first in your layout, ReletiveLayout and FrameLayout can be used to provide Z-ordering, So every child which comes later in your layout having higher z value so it goes up.Add android:layout_below = "#id/scrollview_message_text" to your last linearlayout or order your views within in mind of this characteristic of reletivelayout.
How to create a android Layout where you add a smaller imageView on Top of another Image View. but only half way as the image below.
Thank.
this is the sample I try but it does not work:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/imageCover"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="#drawable/big_cover_img" />
<ImageView
android:id="#+id/imageProfile"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignBottom="#+id/imageCover"
android:layout_centerHorizontal="true"
android:src="#drawable/profile_pic" />
<!-- android:layout_alignBottom="#+id/imageCover" -->
</RelativeLayout>
Use FrameLayout as parent and LinearLayout as child with weight property :
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<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_weight="1">
<ImageView
android:id="#+id/imageCover"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="#drawable/big_cover_img" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
</LinearLayout>
</LinearLayout>
<ImageView
android:id="#+id/imageProfile"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:src="#drawable/ic_launcher" />
</FrameLayout>
Set the second view to be below the first then set top margin of the bottom view to -50 dp or whatever value you want it to overlap
i am trying to show the indicator on view pager such a way that indicator become in bottom of the image and align Center horizontal and center vertical I used Frame layout for this purpose but still not getting desired result.. i think i am missing any attribute my XML code is:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/baneer"
android:layout_width="fill_parent"
android:layout_height="140dp"
android:background="#000000"
android:orientation="vertical">
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<android.support.v4.view.ViewPager
android:id="#+id/myfivepanelpager"
android:layout_width="match_parent"
android:layout_height="130dp"
android:layout_gravity="center" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#f6f7f9"
android:orientation="horizontal">
<com.viewpagerindicator.CirclePageIndicator
android:id="#+id/view_indicator"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#android:color/transparent" />
</LinearLayout>
</FrameLayout>
</LinearLayout>
Try this :
android:layout_alignParentBottom="true" instead of android:layout_gravity="bottom"
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" >