尝试在我的视图中创建黑线以分隔文本块但未显示。 文本显示,因为它应该,但我没有看到该行。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