2

I am banging my head against the wall, because I do not understand this!

I need the blue part layout the same height of the contained red text.

This is what I get:

enter image description here

This is what I want:

enter image description here

This is my XML:

 <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical"> <LinearLayout android:id="@+id/camera_container" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="@dimen/single_margin" android:background="@color/post_icons_background" android:orientation="vertical" android:paddingBottom="@dimen/single_margin" android:paddingLeft="@dimen/double_margin" android:paddingRight="@dimen/double_margin" android:paddingTop="@dimen/single_margin"> <ImageView android:layout_width="match_parent" android:layout_height="match_parent" android:src="@drawable/ic_camera" /> </LinearLayout> <LinearLayout android:background="@color/primary_brand_color" android:id="@+id/separator_continer" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="0dp" android:gravity="center_vertical" android:orientation="horizontal" android:padding="0dp" android:weightSum="1"> <View android:layout_width="0dp" android:layout_height="1dp" android:layout_weight="0.4" android:background="@color/secondary_brand_color" /> <TextView style="?android:textAppearanceSmall" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_margin="0dp" android:layout_weight="0.2" android:background="@color/accent_color" android:gravity="center" android:includeFontPadding="false" android:padding="0dp" android:text="or" android:textColor="@color/secondary_brand_color" /> <View android:layout_width="0dp" android:layout_height="1dp" android:layout_weight="0.4" android:background="@color/secondary_brand_color" /> </LinearLayout> <LinearLayout android:id="@+id/gallery_container" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@color/post_icons_background" android:orientation="vertical" android:paddingBottom="@dimen/single_margin" android:paddingLeft="@dimen/double_margin" android:paddingRight="@dimen/double_margin" android:paddingTop="@dimen/single_margin"> <ImageView android:layout_width="match_parent" android:layout_height="match_parent" android:src="@drawable/ic_gallery" /> </LinearLayout> </LinearLayout> 

Thanks!!!!

6
  • What is the id of that blue part? Commented May 21, 2015 at 11:35
  • remove padding bottom in your camera linear layout and check what you get. The upper portion will get removed. Commented May 21, 2015 at 11:35
  • @KishorPawar separator_continer Commented May 21, 2015 at 11:41
  • post your code properly with color and dimen Commented May 21, 2015 at 11:45
  • Tnx that solution help me as well Commented May 21, 2015 at 12:21

6 Answers 6

1

Looks like none of the answer is going to work so here's my catch.

<LinearLayout android:layout_width="wrap_content" android:layout_height="match_parent" <!-- change here if you want the layout to cover the full screen --> android:orientation="vertical"> <LinearLayout android:id="@+id/camera_container" android:layout_width="wrap_content" android:layout_height="0dp" <!-- change here --> android:layout_weight="0.5"> <!-- change here --> </LinearLayout> <LinearLayout android:id="@+id/separator_continer" android:layout_width="match_parent" android:layout_height="wrap_content"> </LinearLayout> <LinearLayout android:id="@+id/gallery_container" android:layout_width="wrap_content" android:layout_height="0dp" <!-- change here --> android:layout_weight="0.5"> <!-- change here --> </LinearLayout> </LinearLayout> 

I copied only the parts that need to be changed, of course you don't have to delete the inner views. You just need to change the attributes I changed.

This way the outer LinearLayout firstly computes the dimension of the center view, which has no layout_weight attributes, and lays it down; then the remaining space is divided equally between camera_container and gallery_container.

Sign up to request clarification or add additional context in comments.

Comments

0

Change your layout like this

 <LinearLayout android:id="@+id/camera_container" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="@dimen/single_margin" android:background="@color/post_icons_background" android:orientation="vertical" android:paddingBottom="@dimen/single_margin" android:paddingLeft="@dimen/double_margin" android:paddingRight="@dimen/double_margin" android:paddingTop="@dimen/single_margin"> <ImageView android:layout_width="match_parent" android:layout_height="match_parent" android:src="@drawable/ic_camera" /> </LinearLayout> <LinearLayout android:background="@color/primary_brand_color" android:id="@+id/separator_continer" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="0dp" android:orientation="horizontal" android:padding="0dp" android:weightSum="1"> <View android:layout_width="0dp" android:layout_height="1dp" android:layout_weight="0.4" android:background="@color/secondary_brand_color" /> <TextView style="?android:textAppearanceSmall" android:layout_width="0dp" android:layout_height="matchparent" android:layout_margin="0dp" android:layout_weight="0.2" android:background="@color/accent_color" android:gravity="center" android:includeFontPadding="false" android:padding="0dp" android:text="or" android:textColor="@color/secondary_brand_color" /> <View android:layout_width="0dp" android:layout_height="1dp" android:layout_weight="0.4" android:background="@color/secondary_brand_color" /> </LinearLayout> <LinearLayout android:id="@+id/gallery_container" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@color/post_icons_background" android:orientation="vertical" android:paddingBottom="@dimen/single_margin" android:paddingLeft="@dimen/double_margin" android:paddingRight="@dimen/double_margin" android:paddingTop="@dimen/single_margin"> <ImageView android:layout_width="match_parent" android:layout_height="match_parent" android:src="@drawable/ic_gallery" /> </LinearLayout> </LinearLayout> 

1 Comment

can you try it now @LisaAnne
0

Use this Layout.

<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="0dp" android:layout_weight="1" android:background="#ff0000"> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#00ff00"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="OR" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:background="#ff0000"> </LinearLayout> </LinearLayout> 

2 Comments

nope Jafar, you are wrong, the android:weightSum is applied to the children
Sorry, my mistake. Updated my answer
0

You can use ,

android:layout_marginTop="Xdp" android:layout_marginBottom="Xdp" 

for your textview.

1 Comment

Tried android:layout_marginTop="0dp" android:layout_marginBottom="0dp" but no success :-((
0

Try this

Option 1:

android:minHeight="50dp" 

in your centre textView

Option 2:

<LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:weightSum="1" xmlns:android="http://schemas.android.com/apk/res/android"> <LinearLayout android:id="@+id/camera_container" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="0.1" android:layout_marginTop="10dp" android:orientation="vertical" android:paddingBottom="10dp" android:paddingLeft="20dp" android:paddingRight="20dp" android:paddingTop="10dp"> <ImageView android:layout_width="match_parent" android:layout_height="match_parent" android:src="@drawable/back" /> </LinearLayout> <LinearLayout android:id="@+id/separator_continer" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="0dp" android:layout_weight="0.8" android:gravity="center_vertical" android:orientation="horizontal" android:padding="0dp" android:weightSum="1"> <View android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="0.4" /> <TextView style="?android:textAppearanceSmall" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="0dp" android:layout_weight="0.2" android:gravity="center" android:includeFontPadding="false" android:text="or" /> <View android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="0.4" /> </LinearLayout> <LinearLayout android:id="@+id/gallery_container" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:paddingBottom="10dp" android:paddingLeft="20dp" android:layout_weight="0.1" android:paddingRight="20dp" android:paddingTop="10dp"> <ImageView android:layout_width="match_parent" android:layout_height="match_parent" android:src="@drawable/back" /> </LinearLayout> </LinearLayout> 

Please check after adding with your background resources

2 Comments

Abhishek, that is not an option unfortunately
then try option 2 @Lisa
0

your parent i.e. First linear vertical layout android:layout_width="match_parent" instead of wrap_content

2 Comments

your parent i.e. First linear vertical layout android:layout_width="match_parent" instead of wrap_content
Tnx that solution help me as well

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.