我在gridview中創建了10x10個網格的Word搜索遊戲。 字母不會完全顯示在每個單元格中。 這裏是Screen shot of gridview with characters filled inAndroid中的Gridview沒有顯示字符
代碼片段如下:
MainActivity.java
公共類MainActivity擴展AppCompatActivity {
GridView gridView;
static final String[] numbers = new String[] {
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J",
"L", "M", "N", "O", "P", "Q", "R", "S", "T", "U",
"W", "X", "Y", "Z", "A", "B", "C", "D", "E", "F",
"L", "M", "N", "O", "P", "Q", "R", "S", "T", "U",
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J",
"L", "M", "N", "O", "P", "Q", "R", "S", "T", "U",
"W", "X", "Y", "Z", "A", "B", "C", "D", "E", "F",
"L", "M", "N", "O", "P", "Q", "R", "S", "T", "U",
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J",
"L", "M", "N", "O", "P", "Q", "R", "S", "T", "U",
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gridView = (GridView) findViewById(R.id.gridView1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, numbers);
gridView.setAdapter(adapter);
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
Toast.makeText(getApplicationContext(),
((TextView) v).getText(), Toast.LENGTH_SHORT).show();
}
});
}
}
activity_main.xml中
<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:id="@+id/gridView1"
android:numColumns="10"
android:gravity="center"
android:columnWidth="50dp"
android:stretchMode="columnWidth"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context="in.viyanservices.wordsearch1.MainActivity">
</GridView>
我跟着這個教程:http://www.mkyong.com/android/android-gridview-example/。他使用了android:numColumns =「auto_fit」。我正在使用android:numColumns =「10」
您的迴應將不勝感激!非常感謝!
我想看到整個電網在一個屏幕。你的建議會讓用戶水平滾動。對? –
無法在小分辨率設備的單屏中顯示10列。 –