ViewFlipper height issue - android

In following code the viewflipper is not taking the whole screen it just wraps around the textview. why is this happening ?
<?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" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0000ff" >
<ViewFlipper android:id="#+id/ViewFlipper01"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#aa0000"
android:layout_gravity="center">
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"></TextView>
</ViewFlipper>
</ScrollView>
</LinearLayout>

In scrollView use
android:fillViewport="true"

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0000ff" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ViewFlipper android:id="#+id/ViewFlipper01"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#aa0000"
android:layout_gravity="center">
<TextView
android:layout_width="match_parent"
android:layout_height="50dp">
</TextView>
</ViewFlipper>
</LinearLayout>
</ScrollView>
this will work.

Why do you want to increase View Flippers height? View Flipper depends upon the content or views you add inside it..So the height and width of view flipper will be always equal to the largest height/width your provide to the views. In your case its text view so if you increase the height of the current view or add another textView with height greater than the current one view flipper will be increased.

Related

android make view to wrap content but not larger than a specific size

I have a Relative View which has two children an scroll view and a button below it now i want to do this: i want this view to wrap it's content and does not make empty space and also not to exceed screen size.
how can i do that? can any one help?
here is my current layout file which is not working.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ScrollView
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="wrap_content">
....
</ScrollView>
<Button
android:id="#+id/action"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/content"
... />
</RelativeLayout>
RelativeLayout does not have such possibility. However LinearLayout does. Just set LinearLayout's android:orientation to vertical, set ScrollView's android:layout_weight to 1, and it should be working:
<?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="wrap_content"
android:orientation="vertical">
<ScrollView
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
</ScrollView>
<Button
android:id="#+id/action"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
You should use LinearLayout and adjust both the views according to a weight.In that way it will not exceed in any resolution and will adjust acording to the size of screen.
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<ScrollView
android:fillViewPort="true"
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="4"
</ScrollView>
<Button
android:id="#+id/action"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_below="#id/content"
... />
</LinearLayout>
You should make action button align at the bottom and that scroll view should be above that button. In this way scroll view will always be in screen and also button will be visible.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/action"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
... />
<ScrollView
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_above="#id/action"
android:layout_height="match_parent">
....
</ScrollView>
</RelativeLayout>

Foreground view touch to pass lower layers (view behind)

I have layout in the background with view pager and on top of that i have layout which has the text layout.Since background view has view pager and should be visible i have given some padding to the top view.
Here is the layout :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
android:id="#+id/frame"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ViewPager
.... />
<ScrollView
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:paddingTop="150dp"** > <!-- padding to take some space on top>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/rounder_shape"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
... More text views
</LinearLayout>
</LinearLayout>
</ScrollView>
</FrameLayout>
</LinearLayout>
I need to get the view pager to accept touch from the top view or layout.
What i have tried so far :
1) Have tried with InterceptTouch but was not successfull.
2) Also have looked into link Here but it did not help me.

How to scroll a view which is not in scrollview?

I designed a headerlayout(background is transparent) which is not in the scrollview and a scrollview which is in below of that header,in that scrollview have a layout with fixed height 1000dp and in the scrollview i added the views dynamically upto this its fine for me..But my problem is when i scroll the scrollview the background image also moving(background image height is 1550px) at the same time i want to change the background for the header as it is in scrollview background.....
i am not able to implement this please anyone help me in this designing..Below is my designing code..
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/navbar"
android:background="#drawable/navbar_blooptransprant64"
/>
<ScrollView
android:layout_below="#+id/navbar"
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1000dp"
android:background="#drawable/new_bg"
android:orientation="vertical"
>
<LinearLayout
android:id="#+id/outer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
</ScrollView>

Android two latyout horizantally

i want to put two layouts horizantally, small layout on the right and the big on on the left
i tried like this
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="#000000" >
</LinearLayout>
<LinearLayout
android:layout_width="10dip"
android:layout_height="fill_parent"
android:background="#ffffff" >
</LinearLayout>
</LinearLayout>
but still get the small one on the right, what should i do?
A LinearLayout displays its children in the order in which you add them: top to bottom = left to right, for a horizontal view and top to bottom for a vertical view. Change the order of the views in the XML and they will change on the screen.
Sorry to see your comment lately. But try this:
pseudo code(Untested):
<?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:weightsum = "10"
>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="7"
android:background="#ffffff"
>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:background="#000000"
>
</LinearLayout>
</LinearLayout>
You don't need to put orientation horizontal as it supports by default. Even there is no problem if you keep it as the other answerer said.
Try this :
<?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="horizontal" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#000000" >
</LinearLayout>
<LinearLayout
android:layout_width="20dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#ffffff" >
</LinearLayout>
</LinearLayout>
Reference :
The use of layout_weight with Android layouts
Thanks.

linearlayout centered vertically between two linearlayout

I need to do a layout like the one in the picture, using 3 linearlayout, or relativelayout or whatever similar. The linearlayout in the middle has to adapt the height depending on the free space between the first ll one the top and the third ll at the bottom.
The ll at the bottom has to be fixed there.
How can I do?
Thanks, Mattia
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</LinearLayout>
</LinearLayout>
The important thing here is the android:layout_weight="1" in the second layout
Use 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" >
<LinearLayout
android:id="#+id/ui_main_header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:orientation="horizontal"/>
<LinearLayout
android:id="#+id/ui_main_footer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal"/>
<LinearLayout
android:id="#+id/ui_main_center"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#id/ui_main_header"
android:layout_above="#id/ui_main_footer"
android:orientation="vertical"/>
</RelativeLayout>

Categories

Resources