I have one main linear layout with orientation set to vertical. It contains two linear layouts, first with layout_weight = 0.25 and the second with value layout_weight = 0.75. The first layout has horizontal orientation and also has two objects ImageView with value layout_weight = 0.5 and EditText with value layout_weight = 0.5.
Here is the full code:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- top layout -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.25"
android:orientation="horizontal" >
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".5"
app:srcCompat="#drawable/samurai" />
<EditText
android:id="#+id/text"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="right"
android:layout_weight="0.5"
android:background="#android:color/transparent"
android:gravity="bottom|right"
android:inputType="none"
android:maxLines="1"
android:text=""
android:textColor="#color/text"
android:textSize="50sp" />
</LinearLayout>
<!-- bottom layout -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.75"
android:orientation="horizontal">
</LinearLayout>
</LinearLayout>
My question is how can i scale the image to match the width, but to auto-scale the height?
To crop the image according to your expected result, you probably have to use a custom matrix for the imageview. I think this is the simplest implementation for TOP_CROP which you can modify for your needs:
https://stackoverflow.com/a/38049348/7554387
The problem is you add 0 to some layout_width and layout_height. Change to 0dp and it should work.
In this case,you should use ConstraintLayout as it can reduce nested layout and surely improve your layout performance.
With ConstraintLayout,code would be.
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/img"
android:layout_width="0dp"
android:layout_height="0dp"
android:src="#drawable/samurai"
app:layout_constraintHeight_percent="0.25"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.5"/>
<EditText
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintHeight_percent="0.25"
app:layout_constraintStart_toEndOf="#id/img"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_percent="0.5"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/img"/>
</android.support.constraint.ConstraintLayout>
Related
After adding a ConstraintLayout inside a ScrollView, I noticed that the content remains stuck in the middle of the screen (both horizontally and vertically). I already tried add android:layout_gravity="top" to the main ConstraintLayout but that didn't work. Is there something else I can use to position the content at the top?
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/cl_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingStart="#dimen/activity_horizontal_margin"
android:paddingEnd="#dimen/activity_horizontal_margin">
<androidx.cardview.widget.CardView
android:id="#+id/cv_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="30dp"
app:cardUseCompatPadding="true"
app:contentPadding="10dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="#+id/tv_disclaimer">
<LinearLayout
android:id="#+id/ll_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/iv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:importantForAccessibility="no"
android:paddingEnd="10dp" />
<TextView
android:id="#+id/tv_title"
style="#android:style/TextAppearance.Medium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?android:attr/textColorPrimary" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<TextView
android:id="#+id/tv_disclaimer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:gravity="center"
android:textColor="?android:attr/textColorPrimary"
app:layout_constraintTop_toBottomOf="#+id/cv_title"
app:layout_constraintBottom_toTopOf="#+id/cv_description"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
style="#android:style/TextAppearance.Medium" />
<androidx.cardview.widget.CardView
android:id="#+id/cv_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardUseCompatPadding="true"
app:contentPadding="10dp"
app:layout_constraintTop_toBottomOf="#+id/tv_disclaimer"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/cl_description"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/ll_allergies"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="#+id/ll_ingredients">
<ImageView
android:id="#+id/iv_allergies"
android:importantForAccessibility="no"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingEnd="5dp"/>
<TextView
android:id="#+id/tv_allergies"
style="#android:style/TextAppearance.Large"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textColor="?android:attr/textColorPrimary" />
</LinearLayout>
<LinearLayout
android:id="#+id/ll_allergyinfo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintTop_toBottomOf="#+id/ll_allergies"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="#+id/ll_ingredients">
<TextView
android:id="#+id/tv_allergyinfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?android:attr/textColorPrimary"
android:layout_marginBottom="2dp"
android:gravity="start"
style="#android:style/TextAppearance.Medium" />
</LinearLayout>
<LinearLayout
android:id="#+id/ll_ingredients"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintTop_toBottomOf="#+id/ll_allergyinfo"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent">
<ImageView
android:id="#+id/iv_ingredients"
android:importantForAccessibility="no"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingEnd="5dp" />
<TextView
android:id="#+id/tv_ingredients"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textColor="?android:attr/textColorPrimary"
style="#android:style/TextAppearance.Large" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
Current result
Two important things are going on here.
The first is that your ScrollView specifies android:fillViewport="true". This means that whenever the contents of the ScrollView are "smaller" than the screen size, they will be stretched to fill the screen. In other words, your wrap_content ConstraintLayout will only actually wrap its content when you have to scroll. In all other cases, your ConstraintLayout will functionally be match_parent in height.
The second is that the constraints on your CardView, TextView, and second CardView form a vertical chain. Chains have special behavior regarding spacing when the parent is larger than the sum of the views in the chain (which it is due to the fillViewport behavior discussed above); the default is "spread", which will position the three views such that all the remaining space is evenly divided into four chunks (one at the start of the chain, one between the first two views, one between the second two views, and the last at the end of the chain).
How to fix it, though?
The best thing to do is to break the chain. Assuming you just want the views all stacked one after the other, starting from the top of the screen, there's no need to use a chain. To break the chain, remove the bottom constraint from each view:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
...>
<androidx.constraintlayout.widget.ConstraintLayout
...>
<androidx.cardview.widget.CardView
android:id="#+id/cv_title"
...
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent">
...
</androidx.cardview.widget.CardView>
<TextView
android:id="#+id/tv_disclaimer"
...
app:layout_constraintTop_toBottomOf="#+id/cv_title"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<androidx.cardview.widget.CardView
android:id="#+id/cv_description"
...
app:layout_constraintTop_toBottomOf="#+id/tv_disclaimer"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent">
...
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
Alternatively, you could delete the fillViewport attribute from your ScrollView. Without this, the child ConstraintLayout won't ever be stretched to fill the screen, and wrap_content will mean that there's never any extra space to spread out between your chain views.
Try removing app:layout_constraintTop_toTopOf="parent" from your ll_allergies LinearLayout. When copied on my AS it was this line that was adding the unnecessary space between the textview and the layout. Alternatively, keep the constraint and add 0dp on its height so that it enforces the constraint.
UPDATE after comment: I think your views are overlapping because the bottom constraint of ll_allergies is on the top of ll_ingredients instead of ll_allergyinfo. Try changing this:
app:layout_constraintBottom_toTopOf="#id/ll_ingredients"
to this:
app:layout_constraintBottom_toTopOf="#id/ll_allergyinfo"
and bring back the wrap_content of ll_alergies. Hopefully, now everything will fall into place
Update: response no longer valide after the code was updated
There are some errors in your code:
1.you set the layout to be to bottom of itself
android:id="#+id/ll_ingredients"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintTop_toBottomOf="#+id/ll_ingredients"`
the id "ll_alighting" is not defined
How to make View FrameLayout fill all remaining space in ConstraintLayout
I have xml like:
<ImageView
android:background="#FF0000"
android:id="#+id/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_header"
android:scaleType="fitXY"
android:adjustViewBounds="true"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_default="wrap"
app:layout_constraintWidth_default="spread"/>
<FrameLayout
android:background="#00FF00"
app:layout_constraintHeight_default="spread"
app:layout_constraintWidth_default="wrap"
app:layout_constraintTop_toBottomOf="#id/header"
app:layout_constrainedHeight="true"
app:layout_constraintBottom_toTopOf="#id/footer"
android:id="#+id/task_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<LinearLayout
android:background="#FFFF00"
android:orientation="vertical"
android:id="#+id/footer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_default="spread"
app:layout_constraintWidth_default="spread"
app:layout_constraintBottom_toBottomOf="parent">
<ImageButton
style="?borderlessButtonStyle"
android:id="#+id/btn_ar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:padding="0dp"
android:scaleType="fitXY"
android:adjustViewBounds="true"
android:src="#drawable/ic_ar"/>
</LinearLayout>
There are header, footer and FrameLayout in the middle I want to make FrameLayout to fill all remaining space.
I don't understand, which properties I have to use to expand FrameLayout. Please help me!
EDIT: Or any solution with different layout.
This is really simple. To make any view fill up the available space either horizontally or vertically, just set the layout_width/layout_height to 0dp according to your need.
This work, go with ConstraintLayout because has better performance.
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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">
<ImageView
android:background="#FF0000"
android:id="#+id/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_header"
android:minHeight="30dp"
android:scaleType="fitXY"
android:adjustViewBounds="true"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_default="wrap"
app:layout_constraintWidth_default="spread"/>
<FrameLayout
android:id="#+id/task_fragment"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#00FF00"
android:orientation="vertical"
app:layout_constrainedHeight="true"
app:layout_constraintBottom_toTopOf="#+id/btn_ar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_default="spread"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/header"
app:layout_constraintWidth_default="wrap">
</FrameLayout>
<ImageButton
android:id="#+id/btn_ar"
style="?borderlessButtonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:padding="0dp"
android:scaleType="fitXY"
android:src="#drawable/ic_ar"
app:layout_constraintBottom_toBottomOf="parent" />
</android.support.constraint.ConstraintLayout>
<FrameLayout
android:id="#+id/task_fragment"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#00FF00"
android:orientation="vertical"
app:layout_constrainedHeight="true"
app:layout_constraintBottom_toTopOf="#+id/btn_ar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_default="spread"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/header"
app:layout_constraintWidth_default="wrap">
</FrameLayout>
This should work.
Explanation:
All you want is to make the top of this FrameLayout constraint to the bottom of the header, and the bottom of this FrameLayout constraint to the top of the footer.
After setting all the constraints, you still need to set the layout param of FrameLayout to match the constraint. In order to do this, you can try to set layout_height to 0dp. This will make the height of FrameLayout have the effect of match_constraint.
For more detail, you can check this doc: https://developer.android.com/reference/android/support/constraint/ConstraintLayout (just search the keyword match constraint and you will find that block), or simply check this similar answer: Set width to match constraints in ConstraintLayout
I have 4 buttons that I space out evenly using layout_weight="1" and layout_width="0dp". However, on large tablet layouts the buttons are too spread out and looks ugly, so I want to set a maxWidth for all of them, and having empty spaces on both sides of the entire LinearLayout instead (so the four buttons are clustered to the center). However, crawling through StackOverflow, many say they don't work together. Is there a way for me to achieve what I want to do above?
tl;dr:
Below a certain width (say, 100dp), all 4 buttons are spaced evenly.
If layout requires buttons to be bigger than 100dp, all 4 buttons are set to 100dp width and stick together, leaving space on both sides of the layout.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="#dimen/layout_height"
android:background="#drawable/layout_background"
android:orientation="horizontal">
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#color/button_background"/>
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#color/button_background"/>
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#color/button_background"/>
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#color/button_background"/>
</LinearLayout>
Try this
<LinearLayout
android:layout_width="match_parent"
android:layout_height="#dimen/layout_height"
android:background="#drawable/layout_background"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:maxWidth="100dp"
android:background="#color/button_background"/>
</LinearLayout>
</LinearLayout>
A simple hack could be
Wrap your button with a Linear layout and set weight to this layout
Set max width to button inside this sub layout
try this one `
<Button
android:background="#color/button_background"
android:layout_height="match_parent"
android:layout_margin="20dp"
android:layout_weight="1"
android:layout_width="0dp" />
<Button
android:background="#color/button_background"
android:layout_height="match_parent"
android:layout_margin="20dp"
android:layout_weight="1"
android:layout_width="0dp" />
<Button
android:background="#color/button_background"
android:layout_height="match_parent"
android:layout_margin="20dp"
android:layout_weight="1"
android:layout_width="0dp" />
<Button
android:background="#color/button_background"
android:layout_height="match_parent"
android:layout_margin="20dp"
android:layout_weight="1"
android:layout_width="0dp" />
`
add margin to each button as you want .
I have a layout across the bottom of my screen with 4 buttons and a Space in the center. The space is there for a FAB to be displayed above it, but when the layout is hidden, I want to shrink the space in the center to 0dp so that the 4 buttons span evenly across the screen.
I tried using a ViewPropertyAnimator to scale the width to 0, but it does not work.
How can I shrink and expand the space in the center of the 4 buttons programatically (and ideally, animated), such that the 4 buttons will resize and move according to the size of the space?
The layout code I'm using is:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#drawable/background"
android:orientation="horizontal">
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#drawable/button_background" />
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#drawable/button_background" />
<Space
android:id="#+id/space"
android:layout_width="100dp"
android:layout_height="match_parent" />
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#drawable/button_background" />
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#drawable/button_background" />
</LinearLayout>
Set it's visibility to GONE
<Space
android:id="#+id/space"
android:layout_width="100dp"
android:layout_height="match_parent"
android:visibility="gone" />
and the simpler animation method it's to add this line to the root tag of the Layout XML file:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#drawable/background"
android:orientation="horizontal"
android:animateLayoutChanges="true">
I've spent years working with GridBagLayout in java, so I thought setting up a simple layout would be easy. After hours of fiddling with nested LinearLayouts, reading tutorials, and looking at RelativeLayout, I'm getting nowhere.
Below is what I want my main menu to look like. I assume this is possible to do, but many things do not make sense to me, for instance increasing weights seems to decrease the amount of space that a View takes up?
One thing I'm considering doing is just using a relative layout, laying everything else without caring about sizes, and then just setting the sizes in my onCreate since I'll know the size of the display and I can just set each element a certain number of pixels. Is that considered bad practice?
I'm just trying to create a layout with a title on top (the text as large it is can be to fill the width of the screen). That should take up the top 30%. Then the next 50% contains two buttons on the left, an area where I want to draw some animations (I assume using a SurfaceView is a good idea), and then two more buttons on the right.
The remaining 20% will be for a banner ad once I figure out how to add those in.
Is this possible to do? Can anyone show me some XML for this?
So thanks to Alok Nair, this was not hard to do ... I just had to set the sizes to 0px and let the layout weights take care of the sizing.
This is what it ended up being:
<LinearLayout
android:background="#drawable/main_menu_background"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="top"
android:id="#+id/mainSectionMenu"
>
<TextView
android:layout_width="match_parent"
android:layout_height="0px"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="LUNA PUMA"
android:id="#+id/mTitleText"
android:layout_gravity="center"
android:textColor="#ffffffff"
android:autoText="false"
android:textSize="50dp"
android:layout_weight=".3"
android:gravity="center"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight=".5">
<LinearLayout
android:orientation="vertical"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight=".25">
<Button
android:layout_width="wrap_content"
android:layout_height="0px"
android:text="Easy"
android:id="#+id/mEasyButton"
android:layout_gravity="center"
android:layout_weight=".5"
android:background="#android:color/transparent"
android:textColor="#ff000000"/>
<Button
android:layout_width="wrap_content"
android:layout_height="0px"
android:text="Medium"
android:id="#+id/mMediumButton"
android:layout_gravity="center"
android:layout_weight=".5"
android:textColor="#ff000000"
android:background="#android:color/transparent"/>
</LinearLayout>
<SurfaceView
android:layout_width="0px"
android:layout_height="match_parent"
android:id="#+id/mAnimationSurfaceView"
android:layout_weight=".5"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight=".25"
>
<Button
android:layout_width="wrap_content"
android:layout_height="0px"
android:text="Hard"
android:id="#+id/mHardButton"
android:layout_gravity="center"
android:layout_weight=".5"
android:textColor="#ff000000"
android:background="#android:color/transparent"/>
<Button
android:layout_width="wrap_content"
android:layout_height="0px"
android:text="More ..."
android:id="#+id/mMoreButton"
android:layout_gravity="center"
android:layout_weight=".5"
android:background="#android:color/transparent"
android:textColor="#ff000000"/>
</LinearLayout>
</LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight=".2">
</FrameLayout>
</LinearLayout>
You will have to use a combination of layouts, and to achieve this you can use either use android:layout_weight parameters to your views or use Android Percent Support Library.
With layout_weight you can specify a size ratio between multiple views. E.g. you have a view1 and a view2. The view1 should use 3/4 of the screen and view2 should use 1/4 of the screen. Then you will set the layout_weight of the view1 to 3 and the layout_weight of the view2 to 1.
To get it work you also have to set the height or width (depending on your orientation) to 0px.
The Android Percent Support Library allows to specify dimensions of views in terms of percentages instead of absolute numbers, or weights.
The library consists of two main layouts which allow nested views to specify percentage based layouts: PercentRelativeLayout and PercentFrameLayout which work much like their non-Percent counterparts.
Once you've incorporated one of these containers into your layout you can then specify attributes in percentages such as app:layout_widthPercent or app:layout_marginTopPercent="25%".
For using it in your app, just add percent support library to your project
dependencies {
compile 'com.android.support:percent:22.2.0'
}
Here is an example layout using this lib:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerview"
style="#style/match"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
style="#style/block"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.AppBarLayout>
<android.support.percent.PercentRelativeLayout
android:layout_marginTop="?attr/actionBarSize"
android:clickable="true"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:id="#+id/row_one_item_one"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_alignParentTop="true"
android:background="#5182bb"
app:layout_heightPercent="15%"
app:layout_widthPercent="30%" />
<View
android:id="#+id/row_one_item_two"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_toRightOf="#+id/row_one_item_one"
android:background="#396190"
app:layout_heightPercent="15%"
app:layout_widthPercent="30%" />
<View
android:id="#+id/row_one_item_three"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_toRightOf="#+id/row_one_item_two"
android:background="#8fb5e1"
app:layout_heightPercent="15%"
app:layout_widthPercent="40%" />
<View
android:id="#+id/row_two_item_one"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_below="#+id/row_one_item_one"
android:background="#d89695"
app:layout_heightPercent="15%" />
<View
android:id="#+id/row_three_item_one"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_below="#+id/row_two_item_one"
android:background="#f9c093"
app:layout_heightPercent="20%"
app:layout_widthPercent="40%" />
<View
android:id="#+id/row_three_item_two"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_below="#+id/row_two_item_one"
android:layout_toRightOf="#+id/row_three_item_one"
android:background="#948957"
app:layout_heightPercent="10%"
app:layout_widthPercent="60%" />
<View
android:id="#+id/row_four_item_one"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_below="#+id/row_three_item_one"
android:background="#ccc2d9"
app:layout_heightPercent="20%"
app:layout_widthPercent="40%" />
<View
android:id="#+id/row_four_item_two"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_below="#+id/row_three_item_two"
android:layout_toRightOf="#+id/row_four_item_one"
android:background="#c3d59e"
app:layout_heightPercent="25%"
app:layout_widthPercent="60%" />
<View
android:id="#+id/row_five_item_one"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_below="#+id/row_four_item_one"
android:background="#948957"
app:layout_heightPercent="10%"
app:layout_widthPercent="40%" />
<View
android:id="#+id/row_five_item_two"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_below="#+id/row_four_item_two"
android:layout_toRightOf="#+id/row_five_item_one"
android:background="#e6e0ec"
app:layout_heightPercent="10%"
app:layout_widthPercent="60%" />
<View
android:id="#+id/row_six_item_one"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_below="#+id/row_five_item_one"
android:background="#f9c093"
app:layout_heightPercent="20%"
app:layout_widthPercent="20%" />
<View
android:id="#+id/row_six_item_two"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_below="#+id/row_five_item_one"
android:layout_toRightOf="#+id/row_six_item_one"
android:background="#588fd3"
app:layout_heightPercent="20%"
app:layout_widthPercent="20%" />
<View
android:id="#+id/row_six_item_three"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_below="#+id/row_five_item_two"
android:layout_toRightOf="#+id/row_six_item_two"
android:background="#a6a6a6"
app:layout_heightPercent="25%"
app:layout_widthPercent="60%" />
</android.support.percent.PercentRelativeLayout>
You can get idea from this and use it to implement for your design requirements.