试图在我的视图中创建一条黑线来分隔文本块,但它没有显示出来。文本按原样显示,但我没有看到这条线。
编辑:是否已经测试过按照建议动态添加以及修改我的代码但仍然没有行?我错过了什么吗?
这也是在片段内部,类扩展片段{}
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);
}
}