(此处的所有屏幕截图:http://imgur.com/a/uSQEe)
嗨,我正在为“使命召唤:黑色行动2”制定完整的指南。
我已经基于ScrollViews
和GridViews
构建了布局,并使用了ActionBarSherlockLibrary和SlidingMenu库:它在Android 4.0+中运行良好。
但我在旧版Android中的Scroll(ScrollViews和GridViews)都存在问题。
首先,我在我的Corby智能手机(Android 2.2)上进行了测试,而ScrollView根本无效。
第二个我在Android 2.3模拟器上测试过:相同的故障。
这是基于GridView
的此活动的Java代码 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代码:
<?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;
}
}
`
答案 0 :(得分:0)
你先在这里搜索吗?看看this主题。你可能会得到答案 是的,正如@CommonsWare所说,它不是直接可能的。但有一种解决方法。
答案 1 :(得分:0)
一条建议,使用strings.xml存储静态字符串。