我有一个问题,我在同一个布局中有一个带有XML风格的4个按钮,当我运行应用程序并点击一个按钮时,响应时间约为3秒,然后所有按钮立即响应。
所有4个按钮都有一个非常简单的Onclick代码,它将另一个XML代码应用于其他3个按钮。
为所有4个按钮点击代码相同:
answer1.setOnClickListener(new View.OnClickListener() {
@SuppressLint("NewApi")
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
numberClicked++;
if(trueanswernumber == 1)
trueanswer = true;
else trueanswer = false;
answer1.setBackground(getResources().getDrawable(R.drawable.answerclicked));
answer2.setBackground(getResources().getDrawable(R.drawable.answerbutton));
answer3.setBackground(getResources().getDrawable(R.drawable.answerbutton));
answer4.setBackground(getResources().getDrawable(R.drawable.answerbutton));
}
});
" answerclicked" XML代码:
<item android:state_pressed="true" >
<shape android:shape="rectangle" >
<corners android:radius="5dip" />
<stroke android:width="3dip" android:color="#6f1864" />
</shape>
</item>
<item android:state_focused="true">
<shape android:shape="rectangle" >
<corners android:radius="5dip" />
<stroke android:width="2dip" android:color="#6f1864" />
<solid android:color="#125156"/>
</shape>
</item>
<item >
<shape android:shape="rectangle" >
<corners android:radius="3dip" />
<stroke android:width="2dip" android:color="#ffffff" />
</shape>
</item>
&#34; answerbutton&#34; xml代码:
<item android:state_pressed="true" >
<shape android:shape="rectangle" >
<corners android:radius="5dip" />
<stroke android:width="3dip" android:color="#ffffff" />
</shape>
</item>
<item android:state_focused="true">
<shape android:shape="rectangle" >
<corners android:radius="5dip" />
<stroke android:width="2dip" android:color="#ffffff" />
<solid android:color="#125156"/>
</shape>
</item>
<item >
<shape android:shape="rectangle" >
<corners android:radius="3dip" />
<stroke android:width="2dip" android:color="#363636" />
</shape>
</item>
有什么想法吗?