0

我是 Android 的新手,我正在构建一个 MasterDetailFlow 应用程序,问题是我无法更改布局文件(只有默认的 TextView)。我想添加一个 ImageView 和一个 MapView。

请不要忘记我是初学者 :D !

谢谢。

public static final String ARG_ITEM_ID = "item_id";

DummyContent.DummyItem mItem;

public StationDetailFragment() {
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (getArguments().containsKey(ARG_ITEM_ID)) {
        mItem = DummyContent.ITEM_MAP.get(getArguments().getString(ARG_ITEM_ID));
    }

}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_station_detail, container, false);
    if (mItem != null) {
        ((TextView) rootView.findViewById(R.id.station_detail)).setText(mItem.title);
    }
    return rootView;
}
4

1 回答 1

1

自动生成的布局文件将仅包含一个文本视图,因此您无法从调色板添加任何新的 stull。

例如

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    style="?android:attr/textAppearanceLarge"
    android:id="@+id/game_detail"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="16dp"
    tools:context=".GameDetailFragment" />

如果您在生成的存根周围添加任何其他布局,您将能够在该 layout.xml 中修改和添加新内容

例子:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_launcher" />

<TextView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/game_detail"
    style="?android:attr/textAppearanceLarge"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="16dp"
    app:context=".GameDetailFragment" />

</LinearLayout>
于 2012-09-30T13:42:36.637 回答