Note that there are some explanatory texts on larger screens.

plurals
  1. POSet child layout width programmatically In ANDROID?
    primarykey
    data
    text
    <p>In my Code I have a XML file having multiple child layouts. Aand I just want to set one of these child layout's width programmatically according to device's screen width. till now I had tried Layout params, setparam, and other methods but it shows null pointer exception on getting layout id.</p> <p>my parent layout is a Relative Layout, and 1st Child Layout is a Linear Layout("for this layout I need to change width")</p> <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/parentlayout" android:layout_width="fill_parent" android:layout_height="fill_parent"&gt; &lt;LinearLayout android:id="@+id/childlayout" android:layout_width="250dip" android:layout_height="fill_parent" android:orientation="vertical" android:background="#153746"&gt; &lt;LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:background="@drawable/sub_title" android:gravity="center_vertical" &gt; &lt;TextView android:id="@+id/menu_header_label" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textStyle="bold" android:text="asd" android:textColor="#ffffff" android:layout_marginLeft="10dip" /&gt; &lt;ImageView android:id="@+id/menu_header" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" /&gt; &lt;/LinearLayout&gt; &lt;ListView android:id="@+id/menu_listview" android:layout_width="fill_parent" android:layout_height="wrap_content" android:divider="@android:color/darker_gray" android:dividerHeight="1dip" android:scrollingCache="false" /&gt; &lt;/LinearLayout&gt; &lt;FrameLayout android:id="@+id/overlay" android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;/FrameLayout&gt; &lt;/LinearLayout&gt; </code></pre> <p>Java Code:-</p> <pre><code> public class SlideMenu extends LinearLayout { // keys for saving/restoring instance state public final static String KEY_MENUSHOWN = "menuWasShown"; private final static String KEY_STATUSBARHEIGHT = "statusBarHeight"; private final static String KEY_SUPERSTATE = "superState"; // Display display = ((WindowManager) getWindowToken()).getDefaultDisplay(); // int width = display.getWidth(); // deprecated // int height = display.getHeight(); // deprecated // float layWidth = (width*70)/100; // //// LinearLayout view= (LinearLayout)findViewById(R.id.childlayout); //// LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) view.getLayoutParams(); //// params.width = 130; //// view.setLayoutParams(params); // view.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, theSizeIWant)); public static class SlideMenuItem { public int id; public Drawable icon; public String label; } </code></pre> <p>here is my code snippet and i comment the part what i tried so far and get any fine result..``</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload