请看下面的代码片段,它适用于android
TableLayout tbL = (TableLayout) findViewById(R.id.moreInfo_table);
tbL.addView(getRow(key, value), new TableLayout.LayoutParams
(TableLayout.LayoutParams.FILL_PARENT,TableLayout.LayoutParams.WRAP_CONTENT));
private TableRow getRow(String key, String value) {
TableRow tbR = new TableRow(this);
try {
TextView keyTV = new TextView(this);
keyTV.setText("Key " );
keyTV.setTextColor(Color.WHITE);
keyTV.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
keyTV.setTextSize(18.0F);
TextView valueTV = new TextView(this);
valueTV.setText("Value " );
valueTV.setTextColor(Color.WHITE);
valueTV.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
valueTV.setTextSize(18.0F);
tbR.addView(keyTV,new TableLayout.LayoutParams
(TableLayout.LayoutParams.WRAP_CONTENT,TableLayout.LayoutParams.WRAP_CONTENT));
tbR.addView(valueTV,new TableLayout.LayoutParams
(TableLayout.LayoutParams.WRAP_CONTENT,TableLayout.LayoutParams.WRAP_CONTENT));
} catch (Exception e) {
e.printStackTrace();
}
return tbR;
}
问题出在哪里?????? !!!
答案 0 :(得分:0)
尝试更改textcolor ;;
keyTV.setTextColor(Color.WHITE);
到
keyTV.setTextColor(Color.BLUE);
可能是您的视图出现但由于白色不可见。
答案 1 :(得分:0)
这是Full xml文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/recipeName_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:gravity="center"
android:text="Recipe Name..."
android:textSize="24sp" />
<TabHost
android:id="@+id/tabhost"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/vidThums"
android:layout_below="@+id/recipeName_view" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</TabWidget>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ScrollView
android:id="@+id/descr"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/vidThums"
android:layout_below="@+id/ingVu" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/descriptionView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="The name came from ..., and so forth"
android:textSize="24sp" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="@+id/ingDet"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/vidThums"
android:layout_below="@+id/ingVu"
android:orientation="vertical" >
<ListView
android:id="@+id/ingridientsList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="5dp"
android:layout_weight=".50"
android:cacheColorHint="#00000000"
android:clickable="true"
android:divider="@drawable/list_divider1"
android:dividerHeight="20dp"
android:drawSelectorOnTop="false"
android:listSelector="@drawable/list_sel1"
android:scrollbars="vertical"
android:soundEffectsEnabled="true" />
</LinearLayout>
<LinearLayout
android:id="@+id/prepMethod"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/vidThums"
android:layout_below="@+id/ingVu"
android:orientation="vertical" >
<ListView
android:id="@+id/prepMethodList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="5dp"
android:cacheColorHint="#00000000"
android:clickable="true"
android:divider="@drawable/list_divider1"
android:dividerHeight="20dp"
android:drawSelectorOnTop="false"
android:listSelector="@drawable/list_sel1"
android:scrollbars="vertical"
android:soundEffectsEnabled="true" />
</LinearLayout>
<TableLayout
android:id="@+id/moreInfo_table"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/list_selector2"
android:scrollbars="vertical"
android:stretchColumns="0,1" >
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/noOfPersons" />
<TextView
android:id="@+id/noPers_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/noOfPersons" />
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/rating" />
<RatingBar
android:id="@+id/recipRatingBar_details"
style="?android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="2dp"
android:layout_marginTop="5dp"
android:numStars="5"
android:rating="3"
android:stepSize="0.5" />
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/prepTime" />
<TextView
android:id="@+id/prepTime_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="20" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/minutes" />
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/noOfRater" />
<TextView
android:id="@+id/noOfRater_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="20" />
</TableRow>
</TableLayout>
<LinearLayout
android:id="@+id/rating_tab"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/vidThums"
android:layout_below="@+id/ingVu"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal|left"
android:text="@string/raterGuid"
android:textSize="18sp" />
<RatingBar
android:id="@+id/recipRatingBar_rate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginBottom="2dp"
android:layout_marginTop="5dp"
android:numStars="5"
android:rating="0"
android:stepSize="0.5" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/submit"
android:textSize="18sp" />
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
<HorizontalScrollView
android:id="@+id/vidThums"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true" >
<LinearLayout
android:id="@+id/videoThumsHolder"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</LinearLayout>
</HorizontalScrollView>
</RelativeLayout>