Ich habe eine tabHost mit 4 verschiedenen Absichten darin. Ich versuche Animation während des Traversierens zwischen Tabs zu sehen. der Code ich verwende ist arbeitet teilweise:Animation zwischen den Tabs bei Verwendung von Intents als Tabs, wie kann ich das tun?
@Override
public void onTabChanged(String tabId) {
// TODO Auto-generated method stub
FrameLayout questionsLayout = (FrameLayout)tabHost.findViewById(android.R.id.tabcontent);
questionsLayout.setAnimation(AnimationUtils.loadAnimation(tabHost.getContext(), R.anim.go_left_in));
}
aber es belebt nur eine Animation, die eine „inanimation“ ist, mag ich auch eine „outAnimation“ auch addieren, wie kann ich das tun.
By the way, ich diesen Code bin mit jeweils Registerkarten hinzufügen:
intent = new Intent().setClass(this, Tabs.class);
intent.putExtra("questions", rawQ);
spec = tabHost.newTabSpec("english").setIndicator(getText(R.string.ingilizce),res.getDrawable(R.drawable.ic_tabs)).setContent(intent);
tabHost.addTab(spec);
Schließlich bin ich api Version 8.
Das letzte Mal bearbeitet, gesamte Code verwendet:
public class Questions extends TabActivity implements OnTabChangeListener {
public static final String TAG = "Questions";
private String macAddr;
private String json;
private TabHost tabHost;
public void onCreate(Bundle savedInstanceState) {
Log.v(TAG, "Activity State: onCreate() " + TAG);
super.onCreate(savedInstanceState);
Bundle extras = getIntent().getExtras();
if (extras != null) {
macAddr = extras.getString("macAddr");
json = extras.getString("json");
}
// Make it fullscreen
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
// parsing json data
Question[] rawQ = parseJson(json);
if (rawQ==null) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(
"Mac address could not found in database, please add it via control panel.")
.setCancelable(false)
.setNegativeButton("Okay",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
Intent i = new Intent(Questions.this, AnrdoinActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
}
});
AlertDialog alert = builder.create();
alert.show();
} else {
setContentView(R.layout.questions);
Resources res = getResources(); // Resource object to get Drawables
tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, Tabs.class);
intent.putExtra("questions", getLanguageQuestions(rawQ, 1));
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost
.newTabSpec("kyrgyz")
.setIndicator(getText(R.string.kirgizca),
res.getDrawable(R.drawable.ic_tabs))
.setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, Tabs.class);
intent.putExtra("questions", getLanguageQuestions(rawQ, 2));
spec = tabHost
.newTabSpec("turkish")
.setIndicator(getText(R.string.turkce),
res.getDrawable(R.drawable.ic_tabs))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, Tabs.class);
intent.putExtra("questions", getLanguageQuestions(rawQ, 3));
spec = tabHost
.newTabSpec("russian")
.setIndicator(getText(R.string.rusca),
res.getDrawable(R.drawable.ic_tabs))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, Tabs.class);
intent.putExtra("questions", getLanguageQuestions(rawQ, 4));
spec = tabHost
.newTabSpec("english")
.setIndicator(getText(R.string.ingilizce),
res.getDrawable(R.drawable.ic_tabs))
.setContent(intent);
tabHost.addTab(spec);
Log.v(TAG, 0+"");
FrameLayout questionsLayout = (FrameLayout) tabHost.findViewById(android.R.id.tabcontent);
Log.v(TAG, 1+""+questionsLayout.getId());
Log.v(TAG, 2+"");
tabHost.setCurrentTab(0);
tabHost.setOnTabChangedListener(this);
}
}
@Override
public void onTabChanged(String tabId) {
// TODO Auto-generated method stub
FrameLayout questionsLayout = (FrameLayout) tabHost.findViewById(android.R.id.tabcontent);
questionsLayout.setAnimation(AnimationUtils.loadAnimation(tabHost.getContext(), R.anim.go_left_in));
}
// Database related elements
private Question[] parseJson(String text) {
JSONArray data = null;
JSONObject groups = null;
String[][] rawData = null;
JSONArray[] questions = null;
Question[] rawQ = null;
try {
data = new JSONArray(text);
questions = new JSONArray[data.length() - 1];
rawQ = new Question[questions.length];
groups = data.getJSONObject(0);
rawData = new String[2][groups.length()];
Iterator it = groups.keys();
int index = 0;
while (it.hasNext()) {
rawData[0][index] = (String) it.next();
rawData[1][index] = groups.getString(rawData[0][index]);
index++;
}
for (int i = 0; i < questions.length; i++) {
questions[i] = data.getJSONArray(i + 1);
String[] s = new String[6];
for (int j = 0; j < s.length; j++) {
s[j] = ((questions[i].getString(3 + j) == null) ? ("")
: (questions[i].getString(3 + j)));
}
rawQ[i] = new Question(questions[i].getInt(0),
questions[i].getInt(1), questions[i].getString(2), s);
}
Log.e(TAG, rawQ[1].getQuestion());
return rawQ;
} catch (JSONException e) {
Log.e(ACTIVITY_SERVICE, e.toString());
return null;
// ctv.setText(data.toString());
} catch (ArrayIndexOutOfBoundsException e) {
Log.e(TAG, e.toString());
return null;
}
}
private Question[] getLanguageQuestions(Question[] Qs,int id){
int count=0;
for(Question q:Qs)
count+=((q.getLanguageId()==id)?(1):(0));
Question [] result = new Question[count];
int index=0;
for(Question q:Qs){
if(q.getLanguageId()==id){
result[index]=q;
index++;
}
}
return null;
}
}
Ich werde es mir ansehen, aber jetzt muss ich die Version 2.2 beibehalten, vielleicht könnte ich FragmentActivity verwenden. Übrigens danke für das Angebot. – guness
Ja, Sie können Fragment Aktivität verwenden. Aus diesem Grund haben wir TabActivity und verwandte Klassen vollständig dokumentiert, sie werden vollständig durch die Fragment-APIs ersetzt und die Support-Bibliothek bietet diese Möglichkeit für alle aktiven Plattformversionen. – hackbod