काम नहीं करता है मैंने शायद सभी पोस्ट और दस्तावेज पढ़े हैं लेकिन मैं अभी भी इस समस्या को हल नहीं कर सकता।addView
मैं मौजूदा (चल रहे) लेआउट को देखने के लिए addView() विधि का उपयोग करना चाहता हूं लेकिन किसी कारण से मैं नहीं कर सकता। मुझे पता है कि यह आसान और बुनियादी होना चाहिए लेकिन फिर भी मैं इसे नहीं कर सकता। तो, कृपया मेरी मदद करो।
यहाँ एक कोड है:
LinearLayout layout = (LinearLayout)findViewById(R.id.mainLayout);
TextView text=new TextView(this);
text.setText("test");
layout.addView(text);
एक कोड है यही कारण है, और नतीजा यह है कि मैं केवल विचारों जो xml फ़ाइल में परिभाषित कर रहे हैं दिखाया गया है। मैंने जो नया दृश्य जोड़ा है, वहां कोई नया दृश्य नहीं है। जब मैं डीबग करता हूं तो मैं इस अतिरिक्त दृश्य को अभिभावक के बच्चे के रूप में देखता हूं जिसमें मैंने इसे जोड़ा है लेकिन यह प्रदर्शित नहीं होता है।
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/mainLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/main1" >
<TextView android:id="@+id/app_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#FFF"
android:text="@string/app_title"
android:textSize="25dp"
android:gravity="center_horizontal"/>
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="@string/main_screen_counter_title"
android:textSize="15dp"
android:textColor="#FFF"
android:gravity="center_horizontal"/>
<TextView android:id="@+id/frontScreenCounter"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#FFF"
android:text="@string/reading"
android:textSize="33dp"
android:gravity="center_horizontal" />
<GridView android:id="@+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="90dp"
android:numColumns="3"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center"
android:textColor="#888"
/>
</LinearLayout>
कृपया मदद:
यहाँmain.xml है। यह मुझे पागल कर देगा!
क्या आप वह लेआउट जोड़ सकते हैं जहां आप 'टेक्स्ट व्यू' जोड़ना चाहते हैं? – Luksprog
हे लुकप्रोग, यह एंड्रॉइड था: LinearLayout विशेषताओं में layout_height = "fill_parent"। अब मैंने पाठ प्रदर्शित किया है लेकिन स्क्रीन के नीचे। इसे शीर्ष पर कैसे रखा जाए? आपने मेरी मदद की है परोक्ष रूप से, लेकिन अभी भी। बहुत कुछ टीएनएक्स। – Majstor
यदि आप किसी निश्चित स्थिति पर 'टेक्स्ट व्यू' रखना चाहते हैं तो आपको 'addView' विधि का एक और स्वाद का उपयोग करना चाहिए जो एक int लेता है, नई स्थिति' कहां रखना है, इस तरह कुछ: 'addView (टेक्स्ट, 0); ' – Luksprog