0

私は問題があります。タブとセクションをナビゲートできるアプリを作成しました。「main.xml」レイアウトをロードし、テキストビューで新しい線形レイアウトを作成しないようにEclipseに指示するにはどうすればよいですか? それは可能ですか?

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class FirstTabFragment extends Fragment
{

private Activity activity;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
    this.activity = getActivity();


    LinearLayout linearLayout = new LinearLayout(activity);
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
    linearLayout.setLayoutParams(params);

    TextView textView = new TextView(activity);
    textView.setText("This is a sample fragment. I am programmatically added");
    linearLayout.addView(textView);

    return linearLayout;
}
    }

私の main.xml コードは次のとおりです。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" 
android:background="@drawable/screenshot1" >

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_marginTop="167dp"
    android:text="Button" />

<Button
    android:id="@+id/Button01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/button1"
    android:layout_below="@+id/button1"
    android:layout_marginTop="44dp"
    android:text="Button" />

4

2 に答える 2

0
final LayoutInflater inflater = (LayoutInflater)getSystemService("layout_inflater");
TextView textView = (TextView)inflater.inflate(R.layout.main,null); 
于 2013-04-30T15:44:16.637 に答える