我的结构是这样的。
主界面XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#990000"
>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/ans_mainTitle"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent" />
</LinearLayout>
<ScrollView
android:id="@+id/ans_mainScrollView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="50dip" >
<LinearLayout
android:id="@+id/ans_mainLay"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
</LinearLayout>
标题模版XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/ans_daoyu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="@+id/ans_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="15dp"
android:text="我是标题" />
<TextView
android:id="@+id/ans_context"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
</LinearLayout>
public class TitleInit {
private Context context;
private String daoyu;
private String title;
private String text;
private String imgPath;
private int message=-1;
private View titleView;
public TitleInit(Context context, String daoyu,
String title, String text, String imgPath) {
this.context = context;
this.daoyu=daoyu;
this.title=title;
this.text=text;
this.imgPath=imgPath;
init();
}
public View getTitleView(){
return titleView;
}
public void init(){
View vtitle=LayoutInflater.from(context).inflate(R.layout.ans_template_title,null);
TextView tvDaoyu=(TextView)vtitle.findViewById(R.id.ans_daoyu);
TextView tvTitle=(TextView)vtitle.findViewById(R.id.ans_title);
TextView tvContext=(TextView)vtitle.findViewById(R.id.ans_context);
if(daoyu!=null && !daoyu.equals("")){
tvDaoyu.setText(daoyu);
}
if(text!=null && !text.equals("")){
tvContext.setText(text);
}
//标题内容可能会重构
if(title!=null && !title.equals("")){
tvTitle.setText(Html.fromHtml(title));
message=1;
}
this.titleView=vtitle;
}
}
/**
* 初始化标题
*/
public void initValue4Title(){
titleLayout = (LinearLayout)findViewById(R.id.ans_mainTitle);
titleLayout.removeAllViews();
TitleInit ti=new TitleInit(this, "", "<p><span style=\"font-family:黑体\"><span style=\"font-size:14px\"><strong>测试标题</strong></span></span></p>", "", "");
View title=ti.getTitleView();
Toast.makeText(this, "初始化标题完成"+title, Toast.LENGTH_LONG).show();
titleLayout.addView(title);
}
但是这里的titleLayout 添加title对象后 在界面上 一直没有任何的显示。。。title对象也不为空。值都在。。
这里该怎么处理??
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
知道了。。。是我的子控件的height的问题。。。 ######