दिखाई नहीं दे रही हैं मैंने गतिशील रूप से तालिका पंक्तियों को जोड़ने के संबंध में कई पोस्ट देखी हैं, लेकिन मुझे यकीन नहीं है कि मैं क्या खो रहा हूं।गतिशील रूप से जोड़ा गया पंक्ति पंक्तियां
जब मैं निम्नलिखित निष्पादित करता हूं, कुछ भी प्रदर्शित नहीं होता है (एप्लिकेशन शीर्षक बार से अलग)।
मेरे लेआउट:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/table_view_test_main"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<ScrollView
android:id="@+id/tvt_scroll"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
>
<RelativeLayout
android:id="@+id/tvt_scroll_relative"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableLayout
android:id="@+id/tvt_tableview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
</TableLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
मेरे गतिविधि:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.table_view);
TableLayout tableLayout = (TableLayout) findViewById(R.id.tvt_tableview);
TableRow tableRow = new TableRow(this);
tableRow.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
TextView column1 = new TextView(this);
column1.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
column1.setBackgroundColor(Color.YELLOW);
column1.setTextColor(Color.BLUE);
column1.setText("Col1 Value");
tableRow.addView(column1);
TextView column2 = new TextView(this);
column2.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
column2.setBackgroundColor(Color.RED);
column2.setTextColor(Color.GREEN);
column2.setText("Col2 Value");
tableRow.addView(column2);
tableLayout.addView(tableRow, new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));
//tl.refreshDrawableState();
//findViewById(R.id.tvt_scroll_relative).refreshDrawableState();
}
दिलचस्प। यह सब मेरे लिए अच्छा लग रहा है (नहीं कि मैं यहां कुछ भी बिल्कुल निश्चित हूं ...)। मैं 'tableLayout' के ऊपर अन्य लेआउट में अन्य 'टेक्स्ट व्यू' को गतिशील रूप से जोड़ने की कोशिश करने की अनुशंसा करूंगा। देखें कि क्या आप दिखाने के लिए * कुछ * प्राप्त कर सकते हैं। यह कैसे संभव होता है, हमें बताएं। –
लाइन तालिका को हटाएं Row.setLayoutParams(); आपके द्वारा टेबलरो को तुरंत चालू करने के बाद, मुझे यह सोचना चाहिए कि मुझे लगता है। अगर यह काम करता है तो मुझे बताएं, ताकि मैं इसे समाधान के रूप में पोस्ट कर सकूं। –
@ यशवंत कुमार, अकेले इसे हटाने में मदद नहीं मिली। ViewGroup.LayoutParams को TableRow.LayoutParams में बदलना या उन्हें पूरी तरह से हटा देना समस्या को हल करता है। – CrackerJack9