我想在我的應用程序中創建一個靜態網格視圖。它應該是5X5尺寸。我知道如何構建它,但我不明白的是,我只想將單個藍色圖像充填到網格的所有行和列中。我只是無法弄清楚如何實現這一點。我認爲,如果我們使用適配器,我們應該有一個圖片列表左右,但我只有一個圖像。創建一個靜態網格視圖
回答
如果你只是想呈現相同的圖像機智5×5
從MainActivity
gv=(GridView) findViewById(R.id.gridView1);
gv.setAdapter(new CustomAdapter(this));
創建activity_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"
android:orientation="vertical"
tools:context=".MainActivity" >
<GridView
android:id="@+id/gridView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView1"
android:numColumns="5" >
</GridView>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25dp"
android:textStyle="bold"
android:text=" Computer Languages..." />
</RelativeLayout>
通話
創建CustomAdapter。
public class CustomAdapter extends BaseAdapter {
int count = 10;
Context context;
private static LayoutInflater inflater=null;
public CustomAdapter(MainActivity mainActivity) {
// TODO Auto-generated constructor stub
context=mainActivity;
inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return count;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View rowView = inflater.inflate(R.layout.image_list, null);
return rowView;
}
}
,爲此佈局,
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_gravity="center"
android:layout_width="88dp"
android:layout_height="88dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:src="@drawable/ic_launcher" />
</LinearLayout>
這正是我想要的。謝謝 –
但我有一個問題,當我設置grid_item的寬度說50 dp它在網格項目 –
設置屬性的圖像視圖之間留出空格android android:id =「@ + id/imageView1」 android:layout_gravity =「center」 android:layout_width =「match_parent」 android:layout_height =「match_parent」 android:src =「@ drawable/ic_launcher」/> – 2016-01-13 11:08:30
- 1. 如何創建一個靜態視圖
- 2. Rails3 - 創建一個靜態網頁?
- 3. 創建一個包含靜態BIT值的MySQL視圖
- 4. 使用itextsharp以pdf格式動態創建網格視圖
- 5. 從另一個模態視圖創建模態視圖失敗
- 6. 動態視圖與一個靜態xml
- 7. Ember.js - 創建一個「表格」視圖
- 8. 從視圖創建一個表格?
- 9. 用UIPageViewController創建一個網格/地圖
- 10. 如何動態創建圖像的網格視圖
- 11. 動態複製/創建一個Asp.NET網格視圖的完整結構
- 12. 創建一個PHP查詢的網格視圖
- 13. 1,2,3,下一個網格視圖頁面創建
- 14. Xamarin:創建一個自定義的網格視圖
- 15. 如何創建一個動態表格視圖我想知道
- 16. 如何從多個靜態庫中創建一個靜態庫?
- 17. 如何創建網格視圖?
- 18. 編程創建網格視圖
- 19. 網格視圖的編程創建
- 20. 動態靜態表格視圖
- 21. 如何動態創建嵌套的網格視圖
- 22. 如何在動態網格視圖中創建分頁
- 23. 創建一個類的靜態實例
- 24. 創建一個靜態表頭
- 25. Rails:創建一個靜態頁面
- 26. 創建一個靜態工廠
- 27. 創建一個靜態菜單欄
- 28. CMake的 - 創建一個靜態庫
- 29. 如何創建一個靜態NSRange?
- 30. Makefile ...創建一個靜態庫
要在網格視圖顯示單個圖像或多個 – KCN
難道你不想想[網格佈局(HTTP://開發商。 android.com/reference/android/widget/GridLayout.html)? – Blunderer
是所有行和列中的單個圖像 –