मैंने इसे विभिन्न विभिन्न कोणों से मारा है। असल में यह बात है:एंड्रॉइड: टेक्स्ट व्यू के लिए लेआउट पैराम्स दृश्य गायब हो जाता है, प्रोग्रामेटिक
मैंने एक्सएमएल में एक इंटरफेस के लिए एक टेम्पलेट डाला है जिसे प्रोग्रामेटिक रूप से चलाने की आवश्यकता है, इसलिए इसे चलाने के दौरान गतिशील रूप से पॉप्युलेट किया जा रहा है।
यहां समस्या यह है कि एक्सएमएल टेक्स्ट व्यू में कुछ लेआउट बदलाव (जो काम करते हैं) और आवश्यक हैं। लेकिन अगर मैं वास्तव में उन्हें कोड में सेट करता हूं, तो टेक्स्ट व्यू भी दिखाई नहीं देता है।
(TextView, वैसे, एक TableRow अंदर है, इस प्रकार कॉल वजन के नीडिंत है।) मैं कोड के लिए संदर्भ के रूप में उपयोग करने के लिए पहले तैयार किया गया है, एक्सएमएल टेम्पलेट यह है, और यह सिर्फ ठीक काम करता है:
<TextView
android:id="@+id/txtviewWhiteBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:background="@drawable/textview_9patch_white"
android:gravity="center"
android:text="75"
android:textColor="@android:color/black"
android:layout_margin="20dp"
android:padding="20dp"
android:textSize="40dp" />
जैसा मैंने कहा, वह पूरी तरह से बताता है। जब मैं कोड में एक ही लेआउट चलाता हूं, और लेआउटपैम लागू करता हूं, तो टेक्स्ट व्यू गायब हो जाता है।
यहाँ प्रासंगिक स्निपेट है:
int textViewExampleID = 9001;
private TextView txtviewExample = new TextView(this);
private void buildTextView(){
LayoutParams paramsExample = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT,1.0f);
txtviewExample.setId(textViewExampleID);
txtviewExample.setBackgroundResource(R.drawable.textview_9patch_white);
txtviewExample.setGravity(Gravity.CENTER);
txtviewExample.setTextColor(getResources().getColor(android.R.color.black));
paramsExample.setMargins(20, 20, 20, 20);
txtviewExample.setPadding(20, 20, 20, 20);
txtviewExample.setTextSize(40);
txtviewExample.setText("customExample");
//if I comment out the following line, this TextView displays.
//if I leave it in, it doesn't display.
txtviewExample.setLayoutParams(paramsExample);
}
मैं वहाँ LayoutParams के लिए उपलब्ध वर्गों के सभी प्रकार है एहसास है, और मैं उन लोगों के साथ सभी LinearLayout.LayoutParams खेलने किया गया है, TableView.LayoutParams, RelativeLayout.LayoutParams, LayoutParams बस अपने आप ... कोई फर्क नहीं पड़ता कि मैं किस कोशिश कर रहा हूं, "setLayoutParams" को कॉल करने का कोई भी प्रयास पूरे टेक्स्ट व्यू को प्रस्तुत करता है। मैंने यहां मंचों को खराब कर दिया है, और मुझे जवाब नहीं मिला है। यह असामान्य नहीं हो सकता है।
आप की कोशिश की है 'TableRow.LayoutParams' http://developer.android.com/reference/android/widget/TableRow.LayoutParams.html –
मैं बस किया था, (यह याद किया कल रात टिप्पणी, दरनीट) और यह काम किया। धन्यवाद आदमी – Octoth0rpe
आपका स्वागत है :) –