2014-02-09 68 views
5

这个应用程序应该显示的图像,其中学生可以计算出总共值多少钱,然后在editText文本框中输入值,然后将该值与存储值进行比较。不幸的是,当我尝试切换活动超过某个点时(有11个活动活动,其中三个显示图像很好),图像开始模糊,硬币难以彼此区分。我不知道这是Java还是XML错误,但是我粘贴了下面的代码。以下是XML代码。Imageview变得模糊

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context=".Ldsm" > 

<LinearLayout 
    android:id="@+id/linearLayout" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentRight="true" 
    android:orientation="vertical" > 

    <Button 
     android:id="@+id/submitButton" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/submit" /> 
</LinearLayout> 

<TextView 
    android:id="@+id/userQuestion" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/linearLayout" 
    android:layout_alignLeft="@+id/userAnswer" 
    android:layout_marginBottom="30dp" 
    android:text="@string/how_many_coins_total" 
    android:textAppearance="?android:attr/textAppearanceMedium" /> 

<EditText 
    android:id="@+id/userAnswer" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/linearLayout" 
    android:layout_alignParentLeft="true" 
    android:layout_marginLeft="16dp" 
    android:ems="10" 
    android:inputType="number" > 

    <requestFocus /> 
</EditText> 

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignLeft="@+id/userQuestion" 
    android:layout_alignParentTop="true" 
    android:layout_marginLeft="50dp" 
    android:layout_marginTop="118dp" > 

</LinearLayout> 

<ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignBottom="@+id/userQuestion" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    android:layout_alignRight="@+id/linearLayout" 
    android:src="@drawable/ic_coin4" /> 

这仅仅是7个屏幕时,他们显示图像看起来模糊的一个。以下是同一活动的Java代码。

package com.example.ldsm3; 

import android.os.Bundle; 
import android.app.Activity; 
import android.app.AlertDialog; 
import android.content.DialogInterface; 
import android.content.Intent; 
import android.view.Menu; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.EditText; 
import com.example.ldsm3.Problem5; 

public class Problem4 extends Activity 
{ 
private final int COIN3_SCREEN_ANSWER = 95; 

public void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_problem4); 

    Button submitButton = (Button)findViewById(R.id.submitButton); 
    submitButton.setOnClickListener(submitButtonListener); 
} 

public boolean onCreateOptionsMenu(Menu menu) 
{ 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.main, menu); 
    return true; 
} 

private OnClickListener submitButtonListener = new OnClickListener() 
{ 
    public void onClick(View arg0) 
    { 
     EditText editText = (EditText)findViewById(R.id.userAnswer); 
     int userAnswerValue = Integer.parseInt(editText.getText().toString()); 

     // Build the Alert Dialog 
     android.app.AlertDialog.Builder alert = new AlertDialog.Builder(Problem4.this); 
     alert.setTitle("Answer"); 
     alert.setCancelable(false); 
     if(userAnswerValue == COIN3_SCREEN_ANSWER) 
     { 
      alert.setMessage("Congratulations!!!"); 
     } 
     else 
     { 
      alert.setMessage("Sorry, that's not right."); 
     } 
     alert.setPositiveButton("OK",new DialogInterface.OnClickListener() 
     { 
      public void onClick(DialogInterface dialog,int id) 
      { 
       Intent nextCoinScreenIntent = new Intent(Problem4.this, Problem5.class); 
       startActivity(nextCoinScreenIntent); 
      } 
     }); 
     alert.show(); 

    } 


}; 

    } 

而且当它在Nexus 10上运行此截图:

enter image description here

请让我知道是否需要任何更多的信息。

回答

3

它看起来像是在提取未针对特定屏幕尺寸设计的图标。您可以通过转到工作区并删除除“可绘制”之外的任何其他文件夹中的每个图标来修复此问题。 (ic_launcher图标除外,因为它允许您在Android应用程序菜单中显示您的应用程序,并且不会模糊)。

2

比您的解决方案更好地确保正确的解析文件在每个文件夹中。妥善解决与以下乘数所需的分辨率,在Android Design documents如图所示:

enter image description here

+0

http://stackoverflow.com/questions/34960124/how-to-add-images/34960342#34960342 –