[英]How to create a grid like ui in android?
我想實現以下用戶界面
屏幕將分成大小相等的8個部分,每個部分都包含一個imageview
我不使用網格視圖,因為它不是畫廊。 感謝您的幫助
我嘗試了以下代碼,但左列和右列不等於
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/share_bg">
<LinearLayout
android:id="@+id/s_leftColumn"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@+id/s_rightColumn"
android:orientation="vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/title" />
<ImageView
android:id="@+id/s_sixMates"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/leaderboard_a" />
<ImageView
android:id="@+id/s_player"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/leaderboard_b" />
<ImageView
android:id="@+id/s_party"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/leaderboard_c" />
</LinearLayout>
<LinearLayout
android:id="@+id/s_rightColumn"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:orientation="vertical" >
<ImageView
android:id="@+id/s_food"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/leaderboard_d" />
<ImageView
android:id="@+id/s_dress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/leaderboard_e" />
<ImageView
android:id="@+id/s_attendant"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/leaderboard_f" />
<ImageView
android:id="@+id/s_ball"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/leaderboard_g" />
</LinearLayout>
</RelativeLayout>
!!!!!!!!!!!!!!更新:!!!!!!!!!!!!!!!!!!!!!!
實施gridview后,圖像大小過大且超出屏幕,如何解決? 謝謝
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/share_bg"
android:columnCount="2"
android:orientation="vertical"
android:rowCount="4" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/title" />
<ImageView
android:id="@+id/s_sixMates"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/leaderboard_a" />
<ImageView
android:id="@+id/s_player"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/leaderboard_b" />
<ImageView
android:id="@+id/s_party"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/leaderboard_c" />
<ImageView
android:id="@+id/s_food"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/leaderboard_d" />
<ImageView
android:id="@+id/s_dress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/leaderboard_e" />
<ImageView
android:id="@+id/s_attendant"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/leaderboard_f" />
<ImageView
android:id="@+id/s_ball"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/leaderboard_g" />
</GridLayout>
更新:使用Ankit解決方案。 不幸的是左右不相等,請參考截圖
使用此代碼作為參考,並替換為可繪制對象。 對我來說工作正常:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="2" >
<LinearLayout
android:id="@+id/s_leftColumn"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/s_sixMates"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/s_player"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/s_party"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:src="@drawable/ic_launcher" />
</LinearLayout>
<LinearLayout
android:id="@+id/s_rightColumn"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<ImageView
android:id="@+id/s_food"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/s_dress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/s_attendant"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/s_ball"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:src="@drawable/ic_launcher" />
</LinearLayout>
</LinearLayout>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.