嘗試在我的視圖中創建黑線以分隔文本塊但未顯示。 文本顯示,因爲它應該,但我沒有看到該行。Android 2.3.3,在視圖中創建一條線
編輯: 已經測試添加動態按建議,也修改我的代碼,但仍然沒有線?我錯過了什麼嗎?
而且這是一個片段裏,類擴展片段{}
XML代碼:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="@+id/travelContainer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
Java代碼:
public class Travel extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.travel_fragment, container, false);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onViewCreated(view, savedInstanceState);
LinearLayout layout = (LinearLayout)view.findViewById(R.id.travelContainer);
TextView text = new TextView(getActivity());
int padding = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,4, getActivity().getResources().getDisplayMetrics());
text.setPadding(padding, padding, padding, padding);
text.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);
text.setTypeface(null, Typeface.BOLD);
text.setText("TITLE");
text.setId(123456789);
layout.addView(text);
/*
View v = new View(getActivity());
LinearLayout.LayoutParams viewLp = new LayoutParams(LayoutParams.FILL_PARENT,1);
viewLp.setMargins(0, 5, 0, 5);
v.setLayoutParams(viewLp);
v.setBackgroundColor(0x000);
*/
View v = getActivity().getLayoutInflater().inflate(R.layout.line, (ViewGroup)getActivity().getCurrentFocus(), false);
layout.addView(v);
text = new TextView(getActivity());
padding = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,4, getActivity().getResources().getDisplayMetrics());
text.setPadding(padding, padding, padding, padding);
text.setTextSize(TypedValue.COMPLEX_UNIT_SP, 10);
text.setText("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.");
layout.addView(text);
}
}
需要以編程方式執行它,因爲我添加了未知數量的視圖。這些項目來自數據庫。 – Patrick
您仍然可以以編程方式膨脹該XML視圖並動態使用它。代碼將會更清潔。有關詳細信息,請參閱編輯。 – Tim
嘗試過,但由於某種原因它仍然不打印行。 – Patrick