У меня есть вкладка с 4 разными намерениями.Я пытаюсь увидеть анимацию при переходе между вкладками.код, который я использую, частично работает:
@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));
}
однако он анимирует только одну анимацию, которая является «inAnimation», я также хочу добавить также «outAnimation», как я могу это сделать.
Кстати, я использую этот код для добавления каждой вкладки:
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);
Наконец, я использую API-версию 8.
Последнее редактирование, весь код:
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;
}
}