我是新的java和android,所以我試圖用drawable佈局和片段做簡單的應用程序。我現在知道如何在應用中加載網站,但我不知道如何在可繪製佈局片段內顯示一些圖片。我希望你們有任何想法,我怎麼能在一個片段中顯示一些圖片。任何幫助表示讚賞。裏面繪圖佈局片段裏面的圖片
這是我photos_fragment:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/txtLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textSize="16sp"
android:text="Photos View"/>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/txtLabel"
android:src="@drawable/ic_photos"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"/>
</RelativeLayout>
這是我PhotosFragment.java:
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class PhotosFragment extends Fragment {
public PhotosFragment(){}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_photos, container, false);
return rootView;
}
}
什麼是我們的代碼將加載'ic_photos'時fragmet將'Activity' – kId 2014-09-27 20:05:51
附加問題的問題是,如何你想添加片段中的某些圖片嗎? 單張圖片查看多張圖片或多張圖片查看不同圖片。 – Chitrang 2014-09-27 21:18:29
我想在單個imageview中添加多張圖片。 – Tarvo 2014-09-27 21:21:15