StackView堆視圖實現疊放效果
布局代碼:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:orientation="horizontal"><StackView android:id="@+id/mStackView" android:layout_width="200dp" android:layout_height="200dp" android:layerType="hardware" android:loopViews="false" />
</LinearLayout></pre>
頁面代碼:
public class StackViewActivity extends Activity { StackView stackView; int[] imageIds = new int[]{R.drawable.c1, R.drawable.c2, R.drawable.c3, R.drawable.c4};@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_stack); stackView = (StackView) findViewById(R.id.mStackView); //創建一個List對象,List對象的元素是Map List<Map<String, Object>> listItems = new ArrayList<Map<String, Object>>(); for (int i = 0; i < imageIds.length; i++) { Map<String, Object> listItem = new HashMap<String, Object>(); listItem.put("image", imageIds[i]); listItems.add(listItem); } //創建一個SimpleAdapter SimpleAdapter simpleAdapter = new SimpleAdapter(this, listItems, R.layout.item_stack_image, new String[]{"image"}, new int[]{R.id.iv_city}); stackView.setAdapter(simpleAdapter); }
}</pre>
本文由用戶 dfd7 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!