0

我正在尝试将所有图像水平均匀分布,评级从其下方开始,但我正在努力做到这一点。有人可以给我看看吗?

public class LevelActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_level);

        GridView gridview = (GridView) findViewById(R.id.gridview);
        gridview.setAdapter(new ImageAdapter(this));

        gridview.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
                Toast.makeText(LevelActivity.this, "" + position, Toast.LENGTH_SHORT).show();
            }
        });
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.level, menu);
        return true;
    }


    public class ImageAdapter extends BaseAdapter {
        private Context mContext;

        public ImageAdapter(Context c) {
            mContext = c;
        }

        public int getCount() {
            return mThumbIds.length;
        }

        public Object getItem(int position) {
            return null;
        }

        public long getItemId(int position) {
            return 0;
        }

        // create a new ImageView for each item referenced by the Adapter
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ImageView imageView;
            if (convertView == null) {  // if it's not recycled, initialize some attributes
                imageView = new ImageView(mContext);
                imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
                imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                imageView.setPadding(8, 8, 8, 8);
            } else {
                imageView = (ImageView) convertView;
            }

            imageView.setImageResource(mThumbIds[position]);
            return imageView;
        }

        // references to our images
        private Integer[] mThumbIds = {
                R.drawable.zero, R.drawable.one,
                R.drawable.two, R.drawable.three,
                R.drawable.four, R.drawable.five,
                R.drawable.zero, R.drawable.one,
                R.drawable.two, R.drawable.three,
                R.drawable.four, R.drawable.five,
                R.drawable.zero, R.drawable.one,
                R.drawable.two, R.drawable.three,
                R.drawable.four, R.drawable.five,
                R.drawable.zero, R.drawable.one
        };
    }
}

在此处输入图像描述 新布局,现在只需要星星。

4

2 回答 2

1

使用网格视图

 <GridView
                android:id="@+id/list_view"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:columnWidth="90dp"
                android:gravity="center"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="5dp"
                android:horizontalSpacing="10dp"
                android:numColumns="auto_fit"
                android:stretchMode="columnWidth"
                android:scrollingCache="false"
                android:animationCache="false"
                android:fastScrollEnabled="true"
                android:verticalSpacing="10dp" />
于 2013-10-11T13:45:33.367 回答
0

试试这样,它可能会帮助你

<RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <ImageButton
            android:id="@+id/levelselection"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerInParent="true"
            android:background="@null"
            android:src="@drawable/icon" />

         <RatingBar
             android:id="@+id/rtbProductRating"
             style="@style/RatingBar" // I dont know what you are using this line
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_centerHorizontal="true"
             android:layout_below="@+id/levelselection"
             android:numStars="3"
             android:rating="2"
             android:paddingTop="20sp" />

    </RelativeLayout>
于 2013-10-11T13:17:16.897 回答