android-layout-weight

android:layout_height 50% of the screen size

自古美人都是妖i 提交于 2019-11-29 20:52:01
I just implemented a ListView inside a LinearLayout, but I need to define the height of the LinearLayout (it has to be 50% of the screen height). <LinearLayout android:id="@+id/widget34" android:layout_width="300px" android:layout_height="235px" android:orientation="vertical" android:layout_below="@+id/tv_scanning_for" android:layout_centerHorizontal="true"> <ListView android:id="@+id/lv_events" android:textSize="18sp" android:cacheColorHint="#00000000" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/tv_scanning_for" android:layout

Android: trying to understand android:layout_weight

五迷三道 提交于 2019-11-28 17:56:33
I'm trying to divide a page in three parts. I'd like to do it in percentage values, however that is not supported by Android. Instead I have to use android:layout_weight . But I have a hard time understanding it and getting it right. Especially how the actual size gets calculated. Is there a way to get a percentage value (0..100%) out of android:layout_weight ? I went through a few cases (see attached screenshot) to describe the problems. The colored fields are all <LinearLayout> with android:layout_height="fill_parent" , because I want the full screen to be divided between those. Case 1 Okay,

Android Linear Layout Weight Programmatically

元气小坏坏 提交于 2019-11-28 09:39:35
I want to add three linear layouts to an activity programatically each of same width. the problem is i am not able to set the weights of these layouts programmatically. I could do this within xml, but I want to do this in program. here is what I want: Here its the solution LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0, 100); lp.weight = 1; See Full Solution LinearLayout ll1, ll2, ll3; /* Find these LinearLayout by ID i.e ll1=(LinearLayout)findViewById(R.id.ll1); */ LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0, 100); lp.weight = 1; ll1.setLayoutParams(lp); ll2

Android: trying to understand android:layout_weight

99封情书 提交于 2019-11-27 10:55:49
问题 I'm trying to divide a page in three parts. I'd like to do it in percentage values, however that is not supported by Android. Instead I have to use android:layout_weight . But I have a hard time understanding it and getting it right. Especially how the actual size gets calculated. Is there a way to get a percentage value (0..100%) out of android:layout_weight ? I went through a few cases (see attached screenshot) to describe the problems. The colored fields are all <LinearLayout> with android

Android how to display 2 listviews in one activity one after the other

China☆狼群 提交于 2019-11-26 12:59:29
I have used this code to display 2 list view one on top of the other. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ListView android:id="@+id/listView1" android:layout_width="match_parent" android:layout_height="fill_parent" android:layout_weight="1" android:background="#f00" > </ListView> <ListView android:id="@+id/listView2" android:layout_width="match_parent" android:layout_height="fill_parent" android:layout_weight="1" android:background="#0f0" > </ListView>

How to set layout_weight attribute dynamically from code?

筅森魡賤 提交于 2019-11-26 10:19:28
How can I set the value for the attribute layout_weight for button in android dynamically from java code ? Erich Douglass You can pass it in as part of the LinearLayout.LayoutParams constructor: LinearLayout.LayoutParams param = new LinearLayout.LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1.0f ); YOUR_VIEW.setLayoutParams(param); The last parameter is the weight. Use LinearLayout.LayoutParams : LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); params.weight = 1.0f; Button button = new Button(this);

Set the layout weight of a TextView programmatically

試著忘記壹切 提交于 2019-11-26 04:07:07
问题 I\'m trying to dynamically create TableRow objects and add them to a TableLayout . The TableRow objects has 2 items, a TextView and a CheckBox . The TextView items need to have their layout weight set to 1 to push the CheckBox items to the far right. I can\'t find documentation on how to programmatically set the layout weight of a TextView item. 回答1: You have to use TableLayout.LayoutParams with something like this: TextView tv = new TextView(v.getContext()); tv.setLayoutParams(new

What is android:weightSum in android, and how does it work?

只谈情不闲聊 提交于 2019-11-25 22:33:48
问题 I want to know: What is android:weightSum and layout weight, and how do they work? 回答1: Per documentation, android:weightSum defines the maximum weight sum, and is calculated as the sum of the layout_weight of all the children if not specified explicitly. Let's consider an example with a LinearLayout with horizontal orientation and 3 ImageViews inside it. Now we want these ImageViews always to take equal space. To acheive this, you can set the layout_weight of each ImageView to 1 and the

Linear Layout and weight in Android

强颜欢笑 提交于 2019-11-25 22:30:01
问题 I always read about this funny weight value in the Android documentations. Now I want to try it for the first time but it isn\'t working at all. As I understand it from the documentations this layout: <LinearLayout android:layout_width=\"fill_parent\" android:layout_height=\"wrap_content\" android:orientation=\"horizontal\"> <Button android:text=\"Register\" android:id=\"@+id/register\" android:layout_width=\"wrap_content\" android:layout_height=\"wrap_content\" android:padding=\"10dip\"