<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF" >
<LinearLayout
android:layout_width="590dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="vertical" >
...
Can I place image as background in bottom Activity (window)? For instance, when scrolling ScrollView, image must be always bottom and visible.
Did you try using RelativeLayouts? Something like:
<RelativeLayout android:width="fill_parent"
android:height="fill_parent"
...>
<WhateverYouWantAtBottom android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
/>
<ScrollView android:layout_width="fill_parent"
android:layout_height="wrap_content">
<whateverYouWantScrollable android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</ScrollView>
</RelativeLayout>
At the bottom you could have an imageview with the image you wanted. No matter how long your content in the scrollview is, the imageview will not budge from the bottom as long as it has the alignParentBottom set as true.
EDIT: In the above code, the <whateverYouWantAtTheBottom> will be in the background as I declared it first. The foreground will be the contents of the scrollView as that was added last in the XML.
i tried this and its work for me
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher"
android:layout_alignParentBottom="true"
/>
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#id/imageView1" >
</ScrollView>
</RelativeLayout>
Related
I am trying to make a layout where there are a LinearLayout and inside it I want a FrameLayout and a button.
I want the button to use the bottom of the linearlayout and to use the maximum width and the enough height for the button, using wrap content.
The other component, the FrameLayout I want to use it the remaining part of the screen.
How can I do it?
Here it the layout so far..
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
android:id="#+id/camera_preview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<Button
android:id="#+id/button_capture"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:onClick="snapIt"
android:text="#string/Capture" />
</LinearLayout>
Is not showing the button :s
Thanks alot in advance ;)
Better to work out with relative layout with button aligned to parent bottom and your frame layout above it occupying the rest space of the screen.Like this
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<FrameLayout
android:id="#+id/camera_preview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/button_capture"/>
<Button
android:id="#+id/button_capture"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="snapIt"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
use the following xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="#+id/button_capture"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="snapIt"
android:layout_alignParentBottom="true"
android:text="capture" />
<FrameLayout
android:id="#+id/camera_preview"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_above="#+id/button_capture"
/>
</RelativeLayout>
i am just trying to make these layout, after compare my layout code and your layout code, i find a different code, there is in my code. Did you missing it or just move it away cause it useless from the layout code ?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<FrameLayout
android:id="#id/flayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/hello_world">
</FrameLayout>
</LinearLayout>
I have a ScrollView in a LinearLayout along with a header LinearLayout on top. I have given the main LinearLayout a background. If I keep the background for the ScrollView everything displays fine. But If I add a lot of content then the ScrollView background stretches. So I want to keep the ScrollView transparent.
But if I remove the background attribute or if I try android:background="#android:color/transparent" the content inside the ScrollView vanishes. All I can see is the header and the background from the outer LinearLayouts.
This is how I want my Views:
<Linear Layout with background image>
<Header Linear Layout>
</Header Linear Layout>
<ScrollView with no background>
<Layouts in Scroll View>
</ScrollView>
Here is the code:
<?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_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/bg"
android:orientation="vertical" >
<include layout="#layout/topbar" />
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
style="#style/Labels"
android:text="#string/posts_add_postcontent" />
<EditText
android:id="#+id/postsAddContent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="#string/posts_add_postcontent_h"
android:inputType="textMultiLine"
android:maxLength="3000"
android:minLines="3" />
</LinearLayout>
</ScrollView>
</LinearLayout>
Note: The header LinearLayout is included via another file:
<?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_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/topbar"
android:layout_width="fill_parent"
android:layout_height="30dip"
android:background="#layout/bgtop_repeat"
android:orientation="horizontal"
android:paddingTop="2dip" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/app_name"
android:src="#drawable/cornerlogo" />
<Button
android:id="#+id/menubuton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="#drawable/menubutton" />
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#layout/headshadow_repeat"
android:orientation="horizontal" />
</LinearLayout>
Thanks in advance :)
Try
android:layout_height="wrap_content"
in included layout
I am displaying a TextView and below that a ListView in one page. My code is:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:id="#+id/widget"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:id="#+id/widgetlay"
android:layout_height="fill_parent">
<TextView
android:id="#+id/txt1"
android:text=""
android:layout_height="wrap_content"
android:layout_width="fill_parent"
>
</TextView>
</RelativeLayout>
<ListView
android:layout_width="match_parent"
android:id="#+id/listlist"
android:layout_height="0dp"
android:layout_weight="1.0">
</ListView>
</RelativeLayout>
Here I am displaying the ListView data dynamically....but in my emulator it is displaying a TextView at the top and then the ListView with scroll...It is not expanding the list and instead it is scrolling with the content which is generated dynamically...Please tell me how to expand the entire ListView....
Thanks in advance
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:gravity="center|center_vertical"
android:orientation="vertical" android:layout_height="fill_parent" android:layout_width="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="status"
android:id="#+id/txtvw1">
</TextView>
<ListView
android:layout_width="fill_parent"
android:id="#+id/listlist"
android:layout_height="fill_parent">
</ListView>
</LinearLayout>
</LinearLayout>
<?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" >
<TextView
android:id="#+id/txtvw1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="status" >
</TextView>
<ListView
android:id="#+id/listlist"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_weight="1">
</ListView>
</LinearLayout>
You have an error here
<ListView
android:layout_width="fill_parent"
android:id="#+id/listlist" //error here
android:layout_height="fill_parent">
</ListView>
the ListView is filled of the LinearLayout
so that you can't get the TextView.
instand of this
you can layout your view as follows:
<ListView
android:layout_width="match_parent"
android:id="#+id/listlist" //error here
android:layout_height="0"
android:layout_weight="1.0>
android:layout_weight="1.0" //this will make the list view filled with the rest of the screem
Further more
I suggest you use "match_parent" instand of "fill_parent"
this WAS CHANGED in the SDK level 8...
OK, now you use the RelativeLayout install of the LinearLayout
So you should add the relationship with your views in your layout.
You can layout as this:
<RelativeLayout
android:id="#+id/widgetlay"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/txt1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="" >
</TextView>
<ListView
android:id="#+id/listlist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/txt1" />
android:layout_below="#id/txt"----Indicate the relationship with the layout
The RelativeLayout does not have the attr "orientation" and "layout_weight". So I don't suggest you to use this layout, It can't be fixed with the screen height in that way.
The good layout is:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/txtvw1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="status" >
</TextView>
<ListView
android:id="#+id/listlist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0" />
Further more, what do you want to layout your views?
This is a part of my work. List view will appear in the middle of your screen and what ever u need at the top, put it in place of header() and things that u need in bottom of the screen , put it in place of footer(). U can use relative layout instead of the linear layout
Hope this helps.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<RelativeLayout android:layout_width="match_parent" android:layout_alignParentTop="true"
android:layout_height="wrap_content" android:id="#+id/layout_header">
<include layout="#layout/header"/>
</RelativeLayout>
<LinearLayout android:layout_width="match_parent" android:gravity="center" android:orientation="horizontal" android:weightSum="1"
android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:id="#+id/layout_footer">
<include layout="#layout/footer" />
</LinearLayout>
<ListView android:id="#android:id/list" android:layout_below="#id/layout_header" android:layout_above="#id/layout_footer"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:visibility="visible" />
<!-- <TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello"
/> -->
</RelativeLayout>
I don't know what is meaning of expanding meaning here, but listView in scroll view dont behave normally. To resolve this issue you need to implement list view outside of scrollview.
I don't quite understand what you mean, but if you want to have the textView scroll with the content of the listView, you need to add it as a header in your listView.
Moreover, it is not a good idea to put a listview in a scrollview, the listview being scrollable, it messes with the scrollview mechanism.
You can NEVER ever place a listview in the SCrollView.It wont behave properly.Instead of it try using LinearLayout TextView ListView < /Linearlayout>
I have a vertical scrollable layout with lots of items, working fine.
I am trying to place a new linearlayout to the bottom of the screen that would NOT be part of the scrollable layout.
That is, it would sit on the buttom (like an adview) independent of the scrollable part.
I was only able to place it inside the scrollView. How can I place it below, so it would always visible ?
Use a RelativeLayout, and organize it like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
android:layout_above="#+id/linearLayoutThatDoesNotScroll" >
<LinearLayout
android:id="#+id/linearLayoutWithLotofContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/linearLayoutThatDoesNotScroll"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" >
</LinearLayout>
</RelativeLayout>
The trick is in the ScrollView placement, at the same time it is aligned with the top of the screen AND above the lower, fixed, LinearLayout. It just works.
something like this :)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ScrollView android:id="#+id/scroll_view"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<LinearLayout android:id="#+id/content"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</ScrollView>
<LinearLayout android:id="#+id/bottom"
android:layout_width="fill_parent"
android:layout_height="10dip" />
</LinearLayout>
You will add your bottom content to the bottom linearLayout with the android:id=bottom :)
If you used a vertical LinearLayout to hold the scrollable layout, then you could add the adview to the LinearLayout below the scrollable layout and it would appear at the bottom of the screen. (assuming your weights are set correctly,and the scroll layout is set to WRAP_CONTENT)
A RelativeLayout would allow you to set the adview to align itself with the bottom of the scrollable layout as well, but you would still need to make sure the scrollable layout was set to WRAP_CONTENT so it didn't automatically take up the entire screen.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="#+id/dialogButtonOK"
android:layout_width="100px"
android:layout_height="wrap_content"
android:text=" Ok "
android:layout_alignParentBottom="true"
android:layout_centerInParent="true"
android:background="#drawable/button_style"
/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:id="#+id/scrView"
android:layout_above="#id/dialogButtonOK"
android:layout_alignParentTop="true"
>
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="*"
android:id="#+id/main_table" >
</TableLayout>
</HorizontalScrollView>
</ScrollView>
</RelativeLayout>
This is worked for me
My layout was perfect until I decided to add a scrollview.
<?xml version="1.0" encoding="utf-8"?>
<TableLayout android:id="#+id/tableLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android">
<ScrollView android:id="#+id/scrollView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:id="#+id/linearLayout1">
<TableLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="#+id/tableLayout1"/>
</LinearLayout>
</ScrollView>
<Button android:layout_width="match_parent" android:id="#+id/button1" android:text="Start" android:layout_height="50dip" android:onClick="getOutput"></Button>
</TableLayout>
I would like the button to stay at the bottom of the screen, I would actually like the scrollview to take up the entire screen. With just the inner table layout it works fine. In the Graphical Layout preview it looks how I want it, but not when I run it.
I would like the scrollview to take up the whole screen except the button, which I'd like to be at the bottom.
you could use RelativeLayout or LinearLayout as Root view. Giving Button more weight. That way ScrollView won't take up the whole thing.
this should work
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical">
<ScrollView android:layout_width="fill_parent" android:layout_height="0dip"
android:layout_weight="1.0">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical"
android:id="#+id/linearLayout1">
<TableLayout android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/tableLayout1"/>
</LinearLayout>
</ScrollView>
<Button android:layout_width="fill_parent" android:layout_height="wrap_content"
android:text="Bottom Button"/>
</LinearLayout>
Try setting ScrollView fillViewport attribute to true.