2

I was going through sample code for media effects in Android samples for API level 23 and found an unusual value (0.93) being assigned to layout_weight for one of the views contained in a LinearLayout.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:orientation="vertical">

<android.opengl.GLSurfaceView
    android:id="@+id/effectsview"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="0.93"/>

Since the layout is not having any other childviews other than android.opengl.GLSurfaceView , does this value (or android:layout_weight itself) has any significance? I tried to change this value randomly and as expected it did not have any impact on layout.

Edit : Added sample code link

Community
  • 1
  • 1
bsguru
  • 432
  • 4
  • 21

1 Answers1

1

If you don't have any more views with weigths nothing would happen. It's depends on it what android:layout_weight exactly does:

With layout_weight you can specify a size ratio between multiple views. E.g. you have a MapView and a table which should show some additional information to the map. The map should use 3/4 of the screen and table should use 1/4 of the screen. Then you will set the layout_weight of the map to 3 and the layout_weight of the table to 1.

To get it work you also have to set the height or width (depending on your orientation) to 0px.

Read this: What does android:layout_weight mean?

So according to your question if you don't have more views with weight, you can also delete this line of code.

EDIT: Thanks for the link. Now I know the reason of this attribute. Mysterious fragment_media_effects.xml layout file might be already inherited in activity_main.xml, where two others views has also weights. If I am right the value of this view should change, not in Layout Editor, but when you open an app with this fragment.

Community
  • 1
  • 1
piotrek1543
  • 19,130
  • 7
  • 81
  • 94
  • Yes , Im aware of the weight concept , but as the google sdk sample is having this code , I am wondering is there any hidden thing here. – bsguru Dec 26 '15 at 18:02
  • I don't know on which sample are talking about (link would be very appreciated), but maybe when they changing the layout they forgot to delete this line – piotrek1543 Dec 26 '15 at 18:06
  • Added link for clarity , yes might be the case. – bsguru Dec 26 '15 at 18:14
  • But I dont think the value changes , as android:layout_weight is defined inside fragment_media_effects.xml , and this fragment will be placed as a whole in activity_main.xml with it almost occupying 2/3 of layout. – bsguru Dec 26 '15 at 18:48
  • change value - let's say to 20 and open the app. Thats all – piotrek1543 Dec 26 '15 at 18:57