How can I achieve this layout in Android? - android

I want to create this layout where there are three equal ImageViews in a linear layout with layout_weight = 1.0 each. I just want to put two circular images on the inner edges aligned center vertically in android. Maybe I cant achieve this in XML or maybe yes. Please help me achieving this properly.

Try this way,hope this will help you to solve your problem.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#android:color/white">
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#android:color/black">
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#android:color/white">
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="right">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher"/>
</LinearLayout>
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="1"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="left">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher"/>
</LinearLayout>
</LinearLayout>
</FrameLayout>

<?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" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#123456"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#654321"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="right"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="30dp"
android:src="#android:drawable/alert_dark_frame" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:src="#android:drawable/alert_light_frame" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</FrameLayout>
</FrameLayout>
</LinearLayout>

Related

I want center layout be on top of right layout in android

I want my center layout be on top of right layout.
I should use linear to have weight and when I add margin the center layout become under right layout.but I want the center to be on top.is there any solution?
that is my code:
<?xml version="1.0" encoding="utf-8"?>
<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="200dp"
xmlns:ProgressWheel="http://schemas.android.com/apk/res-auto"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="7"
>
<LinearLayout
android:layout_width="0dp"
android:layout_height="140dp"
android:layout_weight="2"
android:layout_gravity="center"
android:gravity="center"
android:background="#android:drawable/dialog_holo_dark_frame"
tools:layout_editor_absoluteY="25dp"
tools:layout_editor_absoluteX="0dp">
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:background="#android:drawable/dialog_holo_dark_frame"
android:orientation="vertical"
android:gravity="center"
android:layout_gravity="start"
android:layout_marginLeft="-25dp"
android:layout_marginRight="-25dp"
tools:layout_editor_absoluteY="8dp"
tools:layout_editor_absoluteX="0dp"
android:id="#+id/second"
>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="140dp"
android:layout_weight="2"
android:layout_gravity="center"
android:gravity="center"
android:background="#android:drawable/dialog_holo_dark_frame"
tools:layout_editor_absoluteY="25dp"
tools:layout_editor_absoluteX="0dp">
</LinearLayout>
</LinearLayout>
</RelativeLayout>
thank u.
Layout xml file
<?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="200dp"
android:baselineAligned="true"
android:orientation="horizontal"
android:weightSum="7">
<LinearLayout
android:layout_width="0dp"
android:layout_height="140dp"
android:layout_gravity="center"
android:layout_weight="2"
android:background="#android:drawable/dialog_holo_dark_frame"
android:gravity="center" />
<LinearLayout
android:id="#+id/second"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:layout_marginLeft="-25dp"
android:layout_marginRight="-25dp"
android:layout_weight="3"
android:background="#android:drawable/dialog_holo_dark_frame"
android:gravity="center"
android:orientation="vertical" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="140dp"
android:layout_gravity="center"
android:layout_weight="2"
android:background="#android:drawable/dialog_holo_dark_frame"
android:gravity="center" />
</LinearLayout>
Now in your activity onCreate() method, do this
ViewCompat.setTranslationZ(findViewById(R.id.second), 1);

Android Layout Weight Exactly Twice Of Others

I would like to simply divide a Linear Layout to 3 piece. I did something as in the code below. If I change the weight of second inner layout anything else than 2, it works. But if I change it to 2(two), the second inner layout doesn't appear in the design ?
<LinearLayout
android:id="#+id/Main"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#ffffff"
android:orientation="vertical"
android:gravity="center"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
android:gravity="center"
>
<ImageView
android:id="#+id/HomePageIcon"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:adjustViewBounds="true" />
</LinearLayout>
<LinearLayout
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingHorizontal="33dp"
android:paddingBottom="30dp"
>
</LinearLayout>
Use it like below height set to 0dp when orientation is vertical.
<LinearLayout
android:id="#+id/Main"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#ffffff"
android:orientation="vertical"
android:gravity="center"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#color/colorAccent"
android:layout_weight="1"
>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:background="#color/background_dark"
android:gravity="center"
>
<ImageView
android:id="#+id/HomePageIcon"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:adjustViewBounds="true" />
</LinearLayout>
<LinearLayout
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#color/colorPrimaryDark"
android:orientation="vertical"
android:paddingHorizontal="33dp"
android:paddingBottom="30dp"
>
</LinearLayout>
Use the Constraint Layout and forget the Linear and Relative layout.
Pls try this,
<LinearLayout
android:id="#+id/Main"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#ffffff"
android:orientation="vertical"
android:gravity="center"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center"
>
<ImageView
android:id="#+id/HomePageIcon"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:adjustViewBounds="true" />
</LinearLayout>
<LinearLayout
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:paddingHorizontal="33dp"
android:paddingBottom="30dp"
>
</LinearLayout>
As you are using layout_weight that means your inner layouts will take the height as much as is available to it. So, in that case there is no need of using layout_height = "wrap_content" just change it to android:layout_height="0dp"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/Main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:gravity="center"
android:orientation="vertical"
android:weightSum="4">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"></LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:gravity="center">
<ImageView
android:id="#+id/HomePageIcon"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:adjustViewBounds="true" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical"
android:paddingBottom="30dp"
android:paddingHorizontal="33dp"></LinearLayout>
</LinearLayout>
When you are using weight than use 0dp to android:layout_width or android:layout_height which you want for affect using weight. And its good to use android:weightSum in parent layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/Main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:gravity="center"
android:orientation="vertical"
android:weightSum="4">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"></LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:gravity="center">
<ImageView
android:id="#+id/HomePageIcon"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:adjustViewBounds="true" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical"
android:paddingBottom="30dp"
android:paddingHorizontal="33dp"></LinearLayout>

ScrollView inside RelativeLayout doesn't work

I have a LinearLayout and dynamically created elements in it. I need to make it scrollable if its height will be larger than 0.8 of screen's height. I'm trying to do it like that. Where is my mistake?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:id="#+id/layoutContainer" android:orientation="vertical"
android:baselineAligned="false" android:weightSum="1">
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:scrollbars="vertical"
android:layout_weight="0.85" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:id="#+id/alarmsLayout" android:orientation="vertical"
android:layout_marginTop="70dp" >
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.15">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/addAlarmBtn"
android:src="#drawable/time"
android:layout_marginBottom="15dp" />
</LinearLayout>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layoutContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1"
android:baselineAligned="false"
android:orientation="vertical" >
<ScrollView
android:layout_weight="0.8"
android:layout_width="match_parent"
android:layout_height="0dp"
android:scrollbars="vertical" >
<LinearLayout
android:id="#+id/alarmsLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="70dp"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.15" >
<ImageView
android:id="#+id/addAlarmBtn"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_marginBottom="15dp"
android:src="#drawable/background_button" />
</RelativeLayout>
</LinearLayout>
Try using 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="vertical">
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width ="match_parent"
android:layout_height="0dp"
android:layout_weight="0.8">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/alarmsLayout" android:orientation="vertical"
android:layout_marginTop="70dp" >
</LinearLayout>
</ScrollView>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_marginBottom="15dp"
android:layout_height="0dp"
android:layout_weight="0.2"
android:gravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/addAlarmBtn"
android:src="#drawable/badge" />
</RelativeLayout>
</LinearLayout>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width"match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/alarmsLayout" android:orientation="vertical"
android:layout_marginTop="70dp" >
</LinearLayout>
</ScrollView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="15dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/addAlarmBtn"
android:src="#drawable/time" />
</RelativeLayout>
</RelativeLayout>

ScrollView in second panel not working

I have an Activity that uses AndroidSlidingUpPanel. Now, everything works perfect. However, I would like to add a ScrollView on my second panel to add the same functionality like Maps or Google Music:
For instance,
When the user has a list of directions, he/she may pull up the drawer and scroll the complete instructions.
Now, my attempt:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.sothree.slidinguppanel.SlidingUpPanelLayout
android:id="#+id/sliding_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom" >
<ScrollView
android:id="#+id/card_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" >
<it.gmariotti.cardslib.library.view.CardView
android:id="#+id/food_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="1dp"
android:layout_marginRight="1dp"
android:layout_marginTop="12dp"
android:animateLayoutChanges="true" />
<View
android:layout_width="match_parent"
android:layout_height="15dp" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#eee"
android:clickable="true"
android:focusable="false"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="68dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/name_slide"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:paddingLeft="10dp"
android:text="#string/slide_up"
android:textSize="14sp" />
</LinearLayout>
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<it.gmariotti.cardslib.library.view.CardView
android:id="#+id/food_nutrition_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:animateLayoutChanges="true" />
<View
android:layout_width="match_parent"
android:layout_height="15dp" />
</LinearLayout>
</ScrollView>
</LinearLayout>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>
This, displays fine my content, but does not add the scroll view for the second panel.
What can I do?
Note: According to the documentation of AndroidSlidingUpPanel, there can only be two children under its view. I use a LinearLayout as the second child because its the only way that I have found to display the drawer. For instance, that TextView would be in the place of the content of the estimated time (drawer) from Maps.
Thanks
Height of second scrollview should be android:layout_height="match_parent". Good luck!
take one RelativeLayout in com.sothree.slidinguppanel.SlidingUpPanelLayout and set property layout_above="yoursecondLinearlayout" to First ScrollView and second child LinearLayout to set property alignParentBottom=true. thats it....
See below code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.sothree.slidinguppanel.SlidingUpPanelLayout
android:id="#+id/sliding_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom" >
**<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >**
<ScrollView
android:id="#+id/card_scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent"
**android:layout_above="#+id/linearlayout1"**>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<it.gmariotti.cardslib.library.view.CardView
android:id="#+id/food_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="1dp"
android:layout_marginRight="1dp"
android:layout_marginTop="12dp"
android:animateLayoutChanges="true" />
<View
android:layout_width="match_parent"
android:layout_height="15dp" />
</LinearLayout>
</ScrollView>
<LinearLayout
**android:id="#+id/linearlayout1"**
**android:layout_alignParentBottom="true"**
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#eee"
android:clickable="true"
android:focusable="false"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="68dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/name_slide"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:paddingLeft="10dp"
android:text="#string/slide_up"
android:textSize="14sp" />
</LinearLayout>
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<it.gmariotti.cardslib.library.view.CardView
android:id="#+id/food_nutrition_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:animateLayoutChanges="true" />
<View
android:layout_width="match_parent"
android:layout_height="15dp" />
</LinearLayout>
</ScrollView>
</LinearLayout>
</RelativeLayout>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>
Fixed it by adding an id to the Parent of the Title, and adding this to my code:
layout.setDragView((LinearLayout) findViewById(R.id.scrolled_view));
New .xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.sothree.slidinguppanel.SlidingUpPanelLayout
android:id="#+id/sliding_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom" >
<ScrollView
android:id="#+id/card_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" >
<it.gmariotti.cardslib.library.view.CardView
android:id="#+id/food_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="1dp"
android:layout_marginRight="1dp"
android:layout_marginTop="12dp"
android:animateLayoutChanges="true" />
<View
android:layout_width="match_parent"
android:layout_height="15dp" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#eee"
android:clickable="true"
android:focusable="false"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/scrolled_view"
android:layout_width="match_parent"
android:layout_height="68dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/name_slide"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:paddingLeft="10dp"
android:text="#string/slide_up"
android:textSize="14sp" />
</LinearLayout>
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<it.gmariotti.cardslib.library.view.CardView
android:id="#+id/food_nutrition_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:animateLayoutChanges="true" />
<View
android:layout_width="match_parent"
android:layout_height="15dp" />
</LinearLayout>
</ScrollView>
</LinearLayout>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>

positioning layout in android

I have something like to this:
I want that when the relative_layout stretch to fill the screen, stretch layout_content (layout_header and layout_footer not resize).
And when the screen size is smaller than layouts then scrool
My code currently looks like this:
<ScrollView android:layout_width="fill_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/layout_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center">
...
</LinearLayout>
<LinearLayout
android:id="#+id/layout_center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_below="#+id/layout_header">
...
</LinearLayout>
<LinearLayout
android:id="#+id/layout_footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_below="#+id/layout_center">
...
</LinearLayout>
</RelativeLayout >
</ScrollView>
Excuse my english, thank you very much. I Wear long time without this fix and have tried with different layout.
Try this..
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/layout_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="top"
android:textSize="20dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/layout_center"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="center"
android:textSize="20dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/layout_footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="bottom"
android:textSize="20dp" />
</LinearLayout>
</LinearLayout>
</ScrollView>
Place the ScrollView only for LinearLayout
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/layout_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center">
...
</LinearLayout>
<ScrollView android:layout_width="fill_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:id="#+id/layout_center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_below="#+id/layout_header">
...
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/layout_footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_below="#+id/layout_center">
...
</LinearLayout>
</RelativeLayout >

Categories

Resources