2012-08-27 27 views
0

我是Android新手,我正在構建一個MasterDetailFlow應用程序,問題是我無法更改佈局文件(只有默認的TextView)。 我想添加一個ImageView和一個MapView。將ImageView添加到MasterDetailFlow示例

請不要忘記我是初學者: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; 
} 
+0

你能添加你的示例代碼嗎? –

回答

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>