0

I want to create a gap between two children of linearLayout.

I don't want to use margin or padding, as this will not scale properly

when I switch to landscape.

I prefer using weight. But then, how to create a dummy (gap only) view in between them?

by the way, what happens if I don't create a landscape xml and

change the device orientation from portrait to landscape?

UPDATE 1

I have tried:

<LinearLayout
    android:id="@+id/layout_information"
    android:layout_width="0dp"
    android:layout_height="fill_parent"
    android:layout_weight="0.47"
    android:orientation="vertical" 
    android:gravity="center"
    >

    <TextView
        android:id="@+id/text_view_destination"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="\@ Home in"
        android:textColor="@color/solid_white"
        android:textSize="19sp"
        android:textStyle="bold" />

    <View
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="0.2"/>

    <TextView
        android:id="@+id/text_view_time"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="40dp"
        android:textColor="@color/solid_white"
        android:textSize="25sp"
        android:textStyle="normal" />
</LinearLayout>

but then

I get warning about nested weighting performance.

I get runtime error when drawing my gadget

Elad Benda
  • 35,076
  • 87
  • 265
  • 471

1 Answers1

0

If you are building for ICS and above, use a Space widget :

<Space
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="YourWeight"/>

(http://developer.android.com/reference/android/widget/Space.html)

Otherwise, you could just use an empty View.

You might also consider if using a RelativeLayout would be more efficient in your case.

When the device is rotated and you don't have a dedicated layout for landscape, your portrait will be used.

FD_
  • 12,947
  • 4
  • 35
  • 62
  • why `RelativeLayout` be more efficient? I still have to create empty view – Elad Benda Jul 28 '13 at 11:53
  • You would not have to create empty views if there are other `Views` you could use as anchors for your `Views`. However, I don't know your exact layout structure, so this was just a suggestion. – FD_ Jul 28 '13 at 11:56
  • I think `match_parent` conflicts with `weight` property – Elad Benda Jul 28 '13 at 11:57
  • As long as all your other views have a `weight`, `match_parent` or `fill_parent` and `weight` won't conflict. – FD_ Jul 28 '13 at 12:00
  • see the answer to this: http://stackoverflow.com/questions/4986861/android-layout-weight – Elad Benda Jul 28 '13 at 12:06
  • The case in this question is different than yours: The OP wanted the `TextView` to only be as wide as its content (`wrap_content`), while you want the gap `View` to fill all the remaining space. – FD_ Jul 28 '13 at 12:11
  • I dont get it. `while you want the gap View to fill all the remaining space.` then why do need weight at all? it fill all the remaining. This is not what i have asked. – Elad Benda Jul 28 '13 at 12:16
  • Btw, I was wrong above, `match_parent` and `weight` even work together if only this one `View` has a `weight`, but the `weight` value will be ignored. – FD_ Jul 28 '13 at 12:16
  • With fill_parent only, the gap view would push all following widgets out of the screen. With a weight value, the gap view will just fill the otherwise empty space, leaving enough space for all following widgets. – FD_ Jul 28 '13 at 12:19