Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/190.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android TextView充气机和Fragmen vis代码_Android - Fatal编程技术网

Android TextView充气机和Fragmen vis代码

Android TextView充气机和Fragmen vis代码,android,Android,列出的代码工作正常,但我还需要一些 @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Log.i(TAG, "HelpDetailsFragment.onCreateView() getCurrentIndex(): "+getCurrentIndex()); Log.i(TAG,

列出的代码工作正常,但我还需要一些

    @Override
public View onCreateView(LayoutInflater inflater,
     ViewGroup container,
     Bundle savedInstanceState)
{
    Log.i(TAG, "HelpDetailsFragment.onCreateView() getCurrentIndex(): "+getCurrentIndex());

    Log.i(TAG, "HelpDetailsFragment.onCreateView() container.getChildCount() first log: "+container.getChildCount());

    FrameLayout frameLayout = new FrameLayout(getActivity());

    TextView headerText = (TextView) new TextView(getActivity());   

    // headerText.inflate(getActivity(), R.id.textView1, null);

    int height = (int) TypedValue.applyDimension(
               TypedValue.COMPLEX_UNIT_DIP, 50, getActivity()
               .getResources().getDisplayMetrics());
    headerText.setHeight(height);
    headerText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 24);
    headerText.setText(HelpScreenData.HELP_HEADERS[getCurrentIndex()]);     

    frameLayout.addView(headerText);

    return  frameLayout;
}

我尝试通过注释行使用XML文件中的值来定制文本外观。
但是这行不通,能不能请人帮忙?

首先,不要那样创建布局!我强烈建议您使用基于XML的布局。然后在
onCreateView()
方法中膨胀XML布局并返回它

例如:

@Override
public View onCreateView(LayoutInflater inflater,
     ViewGroup container,
     Bundle savedInstanceState)
{

    View v = inflater.inflate(R.layout.my_layout, null); //my_layout is your layout defined in XML  

    TextView textView = v.findViewById(R.id.my_textview);
    Button button = v.findViewById(R.id.my_button);
    //do whatever with your textView, set OnClickListener to button etc...        


    return  v; //return inflated layout 
}

我建议您阅读一些关于布局的基本教程

感谢您的回复,但此建议留给我的是:“AndroidRuntime(615):由以下原因引起:java.lang.IllegalStateException:指定的子项已具有父项。您必须首先对子项的父项调用removeView()”这是一条消息,我已经多次收到,不知道如何处理它。请更改行inflater.inflate(R.layout.my_布局,空);带充气器。充气(R.layout.my_布局,容器,假);