我对Android还比较陌生,需要一些代码方面的帮助。
我有一个硬币数组,想要在ScrollView中动态显示硬币的图片。每次用户添加硬币时,视图应该相应地更新。
谢谢!
以下是我想要实现的效果截图 - http://i.imgur.com/3l2fxKw.png
我对Android还比较陌生,需要一些代码方面的帮助。
我有一个硬币数组,想要在ScrollView中动态显示硬币的图片。每次用户添加硬币时,视图应该相应地更新。
谢谢!
以下是我想要实现的效果截图 - http://i.imgur.com/3l2fxKw.png
尝试这个样本
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.activity_main);
LinearLayout linearLayout1 = (LinearLayout) findViewById(R.id.linearLayout1);
for(int x=0;x<3;x++) {
ImageView image = new ImageView(MainActivity.this);
image.setBackgroundResource(R.drawable.ic_launcher);
linearLayout1.addView(image);
}
}
<LinearLayout 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" >
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</LinearLayout>
</ScrollView>
</LinearLayout>
code
(test) - Shmuel看看是否可以使用SurfaceView。
您将拥有画布对象来绘制图像,然后对齐硬币只是将像素适当地映射的问题。
这是一个不错的教程: http://www.mindfiresolutions.com/Using-Surface-View-for-Android-1659.php
GridView
,并自定义适配器。GridView的工作方式类似于ListView。