私の画像が画面に重なり合わずにうまく収まるようにしようとしていますが、何をするにしても適切に拡大することはできません。 私はImageView.ScaleType.CENTER_CROPが画像を拡大すると思っていましたが、おそらくそれはすべて間違っています。 ご協力いただければ幸いです。ここでアンドロイドのレイアウト。画像の列をサイズ変更して画面に収まるようにする
(あなたはその後、私の問題を解決plsはとにかくほとんどのチュートリアルのコードである私のコードを読まずに応答して自由に感じることが簡単な関数を知っていれば)私が得たものである: main.xmlファイル:
<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="75dp"
android:numColumns="auto_fit"
android:verticalSpacing="0dp"
android:horizontalSpacing="1dp"
android:stretchMode="columnWidth"
android:gravity="center"
/>
は、
これは私のHelloGrid.javaファイルです:
package com.grid.example;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.Toast;
public class HelloGrid extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE); //removes annoying title on top
setContentView(R.layout.main);
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(HelloGrid.this, "" + position, Toast.LENGTH_SHORT).show();
}
});
}
}
、これが私のImageAdapter.javaファイルです:
package com.grid.example;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
public class ImageAdapter extends BaseAdapter {
private Context myContext;
public ImageAdapter(Context c) {
myContext = 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
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(myContext);
imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(4, 0, 4, 0);
} else {
imageView = (ImageView) convertView;
}
imageView.setImageResource(mThumbIds[position]);
return imageView;
}
// references to our images
private Integer[] mThumbIds = {
R.drawable.sample_0, R.drawable.sample_3,
R.drawable.sample_4, R.drawable.sample_5,
R.drawable.sample_6, R.drawable.sample_7,
R.drawable.sample_0, R.drawable.sample_1,
R.drawable.sample_2, R.drawable.sample_3,
R.drawable.sample_4, R.drawable.sample_5,
R.drawable.sample_6, R.drawable.sample_7,
R.drawable.sample_0, R.drawable.sample_1,
R.drawable.sample_2, R.drawable.sample_3,
R.drawable.sample_4, R.drawable.sample_5,
R.drawable.sample_6, R.drawable.sample_7,
R.drawable.sample_2, R.drawable.sample_3,
R.drawable.sample_4, R.drawable.sample_5,
R.drawable.sample_6, R.drawable.sample_7,
R.drawable.sample_0, R.drawable.sample_1,
R.drawable.sample_2, R.drawable.sample_3,
R.drawable.sample_4, R.drawable.sample_5,
R.drawable.sample_6, R.drawable.sample_7,
R.drawable.sample_0, R.drawable.sample_1,
R.drawable.sample_2, R.drawable.sample_3,
R.drawable.sample_4, R.drawable.sample_5,
R.drawable.sample_6, R.drawable.sample_7,
R.drawable.sample_2, R.drawable.sample_3,
R.drawable.sample_4, R.drawable.sample_5
};
}
main.xmlファイルでパディングとhorizontalalspacingを編集しようとしました。 私は垂直のスペーシングをうまく取っています。私はちょうど彼らが完全に画面に合うようにサイズを変更する画像に問題があります。
ご回答ありがとうございます。あなたがハードコードされていることを理解するのは難しいですね。 「プログラムによる」UIレイアウトですか?あなたのコード内のレイアウトを膨らませることが何を意味するのでしょうか。たぶん、基本的なレイアウトコードのビットとピースがあれば、わかりやすくなります。 – Xitcod13
私はレイアウトを膨らませる例へのリンクを使って返信を更新しました。 – Kaj