मेरे कोड में मेरे पास एक एक्सएमएल फ़ाइल है जिसमें कई बच्चे लेआउट हैं। और मैं बस डिवाइस की स्क्रीन चौड़ाई के अनुसार इन बाल लेआउट की चौड़ाई प्रोग्रामेटिक रूप से सेट करना चाहता हूं। अब तक मैंने लेआउट पैरा, सेटपरम और अन्य विधियों का प्रयास किया था लेकिन यह लेआउट आईडी प्राप्त करने पर शून्य सूचक अपवाद दिखाता है।एंड्रॉइड में प्रोग्रामेटिक रूप से बाल लेआउट चौड़ाई सेट करें?
मेरे माता-पिता लेआउट एक रिश्तेदार लेआउट, और 1 बच्चा लेआउट एक रेखीय लेआउट ("इस लेआउट के लिए मैं चौड़ाई बदलने की जरूरत है")
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/parentlayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="@+id/childlayout"
android:layout_width="250dip"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#153746">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/sub_title"
android:gravity="center_vertical" >
<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" />
<ImageView
android:id="@+id/menu_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" />
</LinearLayout>
<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" />
</LinearLayout>
<FrameLayout
android:id="@+id/overlay"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</FrameLayout>
</LinearLayout>
जावा कोड है: -
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;
}
यहां मेरा कोड स्निपेट है और मैंने उस भाग पर टिप्पणी की जो मैंने अभी तक कोशिश की है और कोई अच्छा परिणाम प्राप्त करें .. `
कहाँ अपने कोड है? –
अपने एक्सएमएल को स्क्रीनशॉट के रूप में पोस्ट न करें, प्रश्न में वास्तविक कोड डालें। – Cerbrus
इसका उत्तर यहां दिया गया था http://stackoverflow.com/questions/5715612/how-to-set-setlayoutparams-for-linear-layout-elements –