(這裏所有截圖:http://imgur.com/a/uSQEe) 嗨,我正在開發使命召喚一個完整的指南:基於ScrollViews
和GridViews
2. 我已經建立了佈局黑色行動,並使用ActionBarSherlockLibrary和SlidingMenu庫:它在Android 4.0+中運行良好。 但我在Android的舊版本中遇到了Scroll(ScrollViews和GridViews)問題。 首先我已經在我的Corby智能手機(Android 2.2)上測試過了,而ScrollView根本無法工作。 對於第二我已經在Android 2.3模擬器上測試它:同樣的故障。滾動型不工作
這是基於GridView的
佈局 public class MainActivity extends SherlockActivity {
final String pacchetto_app_prenium = Strings.PreniumPackage;
final String prenium = Strings.prenium;
final String free = Strings.free;
private String LicenzaCaricata;
private MissionsGridviewAdapter mAdapter1;
private ArrayList<String> listMaps1;
private ArrayList<Integer> listImages1;
private GridView gridView1;
private static SlidingMenu menu;
final static String pyrrhycvictory = "Pyrrhic Victory";
final static String celerium = "Celerium";
final static String oldwounds = "Old Wounds";
final static String timeandfate = "Time And Fate";
final static String fallenangel = "Fallen Angel";
final static String karma = "Karma";
final static String sufferwithme = "Suffer With Me";
final static String achillesveil = "Achille's Veil";
final static String odysseus = "Odysseus";
final static String cordisdie = "Cordis Die";
final static String judgmentday = "Judgment Day";
final static String strikeforcetraining = "(SF) Strike Force Training";
final static String fobspectre = "(SF) FOB Spectre";
final static String shipwreck = "(SF)Shipwreck";
final static String ied = "(SF)I.E.D.";
final static String secondchange = "(SF)Second Change";
final static String dispatch = "(SF)Dispatch";
String valoreOttenuto;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.c_missions);
prepareList();
AdView adView = (AdView) this.findViewById(R.id.adView);
adView.loadAd(new AdRequest());
menu = new SlidingMenu(context);
menu.setMode(SlidingMenu.LEFT);
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
menu.setShadowWidthRes(R.dimen.shadow_width);
menu.setShadowDrawable(R.drawable.shadow);
menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
menu.setFadeDegree(0.35f);
menu.attachToActivity(activity, SlidingMenu.SLIDING_CONTENT);
menu.setMenu(R.layout.main_slidingmenu);
gridView1 = (GridView) findViewById(R.id.gridView1);
mAdapter1 = new MissionsGridviewAdapter(this, listMaps1, listImages1);
gridView1.setAdapter(mAdapter1);
gridView1.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int position, long arg3) {
valoreOttenuto = mAdapter1.getItem(position);
if (valoreOttenuto.equals(pyrrhycvictory)) {
startClasse(CMpyrrhicVictory.class);
} else if (valoreOttenuto.equals(celerium)) {
startClasse(CMcelerium.class);
} else if (valoreOttenuto.equals(oldwounds)) {
startClasse(CMoldwounds.class);
} else if (valoreOttenuto.equals(timeandfate)) {
Controllo(CMtime_and_fate.class);
} else if (valoreOttenuto.equals(fallenangel)) {
Controllo(CMfallenangel.class);
} else if (valoreOttenuto.equals(karma)) {
Controllo(CMkarma.class);
} else if (valoreOttenuto.equals(sufferwithme)) {
Controllo(CMsufferwithme.class);
} else if (valoreOttenuto.equals(achillesveil)) {
Controllo(CMachillesveil.class);
} else if (valoreOttenuto.equals(achillesveil)) {
Controllo(CMachillesveil.class);
} else if (valoreOttenuto.equals(cordisdie)) {
Controllo(CMcordisdie.class);
} else if (valoreOttenuto.equals(judgmentday)) {
Controllo(CMjudgmentday.class);
} else if (valoreOttenuto.equals(strikeforcetraining)) {
Controllo(CMSstrikeforcetraining.class);
} else if (valoreOttenuto.equals(fobspectre)) {
Controllo(CMSfobspectre.class);
} else if (valoreOttenuto.equals(shipwreck)) {
Controllo(CMSshipwreck.class);
} else if (valoreOttenuto.equals(ied)) {
Controllo(CMSied.class);
} else if (valoreOttenuto.equals(secondchange)) {
Controllo(CMSsecondchange.class);
} else if (valoreOttenuto.equals(dispatch)) {
Controllo(CMSdispatch.class);}
}
});
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setSubtitle("Campaign/");
getSupportActionBar().setTitle("Missions");
// START SLIDING MENU CONTROL
Button c_missions = (Button) findViewById(R.id.c_missions);
c_missions.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
menu.toggle();
}
});
Button c_intels = (Button) findViewById(R.id.c_allintels);
c_intels.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startClasse(Cintels.class);
}
});
Button m_classes = (Button) findViewById(R.id.m_classes);
m_classes.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startClasse(Mclasses.class);
}
});
Button m_scorestreaks = (Button) findViewById(R.id.m_scorestreaks);
m_scorestreaks.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startClasse(Mscorestreaks.class);
}
});
Button m_maps = (Button) findViewById(R.id.m_maps);
m_maps.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startClasse(Mmaps.class);
}
});
Button m_ranks = (Button) findViewById(R.id.m_ranks);
m_ranks.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startClasse(Mranks.class);
}
});
Button m_emblems = (Button) findViewById(R.id.m_emblems);
m_emblems.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startClasse(Memblems.class);
}
});
Button m_callingcards = (Button) findViewById(R.id.m_callingcards);
m_callingcards.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startClasse(Mcallingcards.class);
}
});
Button z_weapons = (Button) findViewById(R.id.z_weapons);
z_weapons.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startClasse(Zweapons.class);
}
});
Button z_maps = (Button) findViewById(R.id.z_maps);
z_maps.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startClasse(Zmaps.class);
}
}); };
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getSupportMenuInflater().inflate(R.menu.mainactivity_actionbar, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
menu.toggle();
break;
case R.id.settings_button:
startClasse(SettingsActivity.class);
break;
case R.id.buy_button:
BuyPRO();
break;
default:
return super.onOptionsItemSelected(item);
}
return true;
}
private void startClasse(Class<?> ClasseDaAvviare) {
Intent intent = new Intent(this, ClasseDaAvviare);
startActivity(intent);
}
private void BuyPRO() {
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse(Strings.LinkProMarket)));
}
private void Dialogo() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(Strings.DialogTitle);
builder.setIcon(R.drawable.icona)
.setMessage(Strings.DialogMessage)
.setCancelable(true)
.setPositiveButton(Strings.DialogPositiveButtonText,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
BuyPRO();
}
})
.setNegativeButton(Strings.DialogNegativeButtonText,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
finishActivity(0);
}
});
AlertDialog alertDialog = builder.create();
alertDialog.show();
;
}
public void prepareList() {
listMaps1 = new ArrayList<String>();
listMaps1.add(pyrrhycvictory);
listMaps1.add(celerium);
listMaps1.add(oldwounds);
listMaps1.add(timeandfate);
listMaps1.add(fallenangel);
listMaps1.add(karma);
listMaps1.add(sufferwithme);
listMaps1.add(achillesveil);
listMaps1.add(odysseus);
listMaps1.add(cordisdie);
listMaps1.add(judgmentday);
listMaps1.add(strikeforcetraining);
listMaps1.add(fobspectre);
listMaps1.add(shipwreck);
listMaps1.add(ied);
listMaps1.add(secondchange);
listMaps1.add(dispatch);
listImages1 = new ArrayList<Integer>();
listImages1.add(R.drawable.m1);
listImages1.add(R.drawable.m2);
listImages1.add(R.drawable.m3);
listImages1.add(R.drawable.m4);
listImages1.add(R.drawable.m5);
listImages1.add(R.drawable.m6);
listImages1.add(R.drawable.m7);
listImages1.add(R.drawable.m8);
listImages1.add(R.drawable.m9);
listImages1.add(R.drawable.m10);
listImages1.add(R.drawable.m11);
listImages1.add(R.drawable.m12);
listImages1.add(R.drawable.m13);
listImages1.add(R.drawable.m14);
listImages1.add(R.drawable.m15);
listImages1.add(R.drawable.m16);
listImages1.add(R.drawable.m17);
}
}
XML代碼這個活動的Java代碼:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal"
android:orientation="vertical" >
<com.google.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="@string/pub_id" >
</com.google.ads.AdView>
<GridView
android:id="@+id/gridView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:numColumns="auto_fit"
android:stretchMode="columnWidth"
tools:listitem="@android:layout/simple_list_item_2" >
</GridView>
</LinearLayout>
代碼爲GridView適配器(MissionsGridviewAdapter)`
import java.util.ArrayList;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
public class MissionsGridviewAdapter extends BaseAdapter {
private ArrayList<String> listCountry;
private ArrayList<Integer> listFlag;
private Activity activity;
public MissionsGridviewAdapter(Activity activity, ArrayList<String> listCountry,
ArrayList<Integer> listFlag) {
super();
this.listCountry = listCountry;
this.listFlag = listFlag;
this.activity = activity;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return listCountry.size();
}
@Override
public String getItem(int position) {
// TODO Auto-generated method stub
return listCountry.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
public static class ViewHolder {
public ImageView imgViewFlag;
public TextView txtViewTitle;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ViewHolder view;
LayoutInflater inflator = activity.getLayoutInflater();
if (convertView == null) {
view = new ViewHolder();
convertView = inflator.inflate(R.layout.c_missions_gridviewrow, null);
view.txtViewTitle = (TextView) convertView
.findViewById(R.id.textView1);
view.imgViewFlag = (ImageView) convertView
.findViewById(R.id.imageView1);
convertView.setTag(view);
} else {
view = (ViewHolder) convertView.getTag();
}
view.txtViewTitle.setText(listCountry.get(position));
view.imgViewFlag.setImageResource(listFlag.get(position));
return convertView;
}
}
`
Android中沒有任何名爲'ScroolView'的東西。如果你的意思是'ScrollView',你沒有使用'ScrollView'。你不需要'ScrollView',因爲'GridView'會根據需要自動垂直滾動。 – CommonsWare 2013-02-24 16:35:26
同樣的問題,如果你找到修復,請編輯。 – 2013-06-06 15:58:53