2012-10-01 15 views
5

में बदल गया है, मैं स्पष्ट रूप से अपने लाइनरलायआउट (@android: रंग/काला का उपयोग करके अपने एक्सएमएल में) का एक काला रंग परिभाषित कर रहा हूं, लेकिन कभी-कभी (अक्सर स्क्रीन रोटेशन के बाद), काला है एक ग्रे रंग (या एक पारदर्शी काला) में बदलना।एंड्रॉइड - ब्लैक बैकग्राउंड ग्रे

यह समस्या कई उपकरणों पर दिखाई देती है: एमुलेटर, एसर तरल (एंड्रॉइड 2.2) और गैलेक्सी नेक्सस (एंड्रॉइड 4.1) दोनों पर।

स्क्रीनशॉट: Buggy view // Not buggy view

यहाँ मेरी एक्सएमएल और गतिविधि कोड है:

एक्सएमएल:

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="150dp" 
      android:minHeight="150dp"> 

      <ImageView 
       android:id="@+id/projectview_description_image" 
       android:layout_width="match_parent" 
       android:layout_height="150dp" 
       android:contentDescription="@string/projectview_description_image_description" 
       android:scaleType="centerCrop" 
       android:src="@drawable/project_nophoto" /> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignParentBottom="true" 
       android:orientation="vertical" 
       android:id="@+id/projectview_description_overlay" 
       android:paddingTop="5dp" 
       android:paddingLeft="10dp" 
       android:paddingBottom="5dp" 
       android:background="@android:color/black" 
       android:height="35dp"> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:id="@+id/projectview_description_title" 
        android:textAllCaps="true" 
        android:textColor="@android:color/white" 
        android:textSize="20dp" 
        android:textStyle="bold"/> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:id="@+id/projectview_description_baseline" 
        android:textColor="@android:color/white" 
        android:textStyle="italic" /> 

      </LinearLayout> 

     </RelativeLayout> 

     <!-- This LinearLayout background is buggy --> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="40dp" 
      android:orientation="horizontal" 
      android:background="@android:color/black"> 

      <ImageView 
       android:layout_width="175dp" 
       android:layout_height="25dp" 
       android:layout_gravity="center_vertical" 
       android:paddingLeft="10dp" 
       android:paddingRight="10dp" 
       android:scaleType="fitCenter" 
       android:src="@drawable/project_status_finish" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center_vertical" 
       android:gravity="right" 
       android:paddingRight="10dp" 
       android:text="@string/projectview_description_website" 
       android:textColor="@color/website_link" 
       android:textSize="15dp" 
       android:id="@+id/projectview_description_website" /> 

     </LinearLayout> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:id="@+id/projectview_description_about_container" 
      android:padding="10dp" 
      android:paddingBottom="0dp"> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="@string/projectview_description_about" 
       android:textAllCaps="true" 
       android:textStyle="bold" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:id="@+id/projectview_description_about_text" /> 

     </LinearLayout> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:id="@+id/projectview_description_questions_container" /> 

    </LinearLayout> 

</ScrollView> 

गतिविधि:

public class ProjectViewActivity extends Activity implements OnClickListener { 
    private boolean displayMenu = false; 
    private Intent shareIntent; 
    private FavoriteSqlite db; 
    private I4pProjectTranslation project; 

    @TargetApi(14) 
    @Override 
    public boolean onPrepareOptionsMenu(Menu menu) { 
     if(displayMenu) { 
      // Inflate menu only if it hasn't been done before 
      if(menu.size() == 0) { 
       // Inflating the menu 
       MenuInflater inflater = getMenuInflater(); 
       inflater.inflate(R.menu.projectview, menu); 

       // Creating share intent 
       Intent prepareShareIntent = new Intent(Intent.ACTION_SEND); 
       prepareShareIntent.putExtra(Intent.EXTRA_TEXT, UriHelper.getProjectUrl(project)); 
       prepareShareIntent.putExtra(Intent.EXTRA_SUBJECT, project.getTitle()); 
       prepareShareIntent.setType("text/plain"); 
       shareIntent = Intent.createChooser(prepareShareIntent, getResources().getText(R.string.projectview_menu_share_dialog)); 
      } 

      // Defining favorite state 
      MenuItem favoriteItem = menu.getItem(0); 
      if(db.isFavorite(project)) 
       favoriteItem.setTitle(R.string.projectview_menu_favorites_remove); 
      else 
       favoriteItem.setTitle(R.string.projectview_menu_favorites_add); 
     } 
     return super.onCreateOptionsMenu(menu); 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     switch(item.getItemId()) { 
     case android.R.id.home: 
      if(getIntent().getData() != null) { 
       Intent intent = new Intent(this, HomepageActivity.class); 
       intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); 
       startActivity(intent); 
      } else 
       finish(); 
      break; 
     case R.id.projectview_favorite: 
      Toast t; 
      if(db.isFavorite(project)) { 
       db.removeFavorite(project); 
       t = Toast.makeText(this, getResources().getString(R.string.projectview_toast_favorites_remove, project.getTitle()), Toast.LENGTH_SHORT); 
      } else { 
       db.addFavorite(project); 
       t = Toast.makeText(this, getResources().getString(R.string.projectview_toast_favorites_add, project.getTitle()), Toast.LENGTH_SHORT); 
      } 
      t.show(); 
      break; 
     case R.id.projectview_share: 
      startActivity(shareIntent); 
      break; 
     } 
     return super.onOptionsItemSelected(item); 
    } 

    @TargetApi(11) 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     if(Build.VERSION.SDK_INT < 11) 
      requestWindowFeature(Window.FEATURE_NO_TITLE); 
     setContentView(R.layout.loading); 
     db = new FavoriteSqlite(this); 

     if(Build.VERSION.SDK_INT >= 11) 
      getActionBar().setDisplayHomeAsUpEnabled(true); 

     project = (I4pProjectTranslation) getLastNonConfigurationInstance(); 
     if(project != null) 
      displayProject(); 
     else { 
      String projectLang; 
      String projectSlug; 

      Uri data = getIntent().getData(); 
      if(data != null) { 
       List<String> path = data.getPathSegments(); 
       projectLang = path.get(0); 
       projectSlug = path.get(2); 
      } else { 
       Bundle extras = getIntent().getExtras(); 

       if(extras.containsKey("project_title")) 
        setTitle(extras.getString("project_title")); 

       projectLang = extras.getString("project_lang"); 
       projectSlug = extras.getString("project_slug"); 
      } 

      ProjectViewHandler handler = new ProjectViewHandler(this); 
      ProjectViewThread thread = new ProjectViewThread(handler, projectLang, projectSlug); 

      thread.start(); 
     } 
    } 

    @Override 
    public Object onRetainNonConfigurationInstance() { 
     return project; 
    } 

    public void setProject(I4pProjectTranslation p) { 
     project = p; 
    } 

    @TargetApi(11) 
    public void displayProject() { 
     setContentView(R.layout.projectview_description); 
     displayMenu = true; 
     if(Build.VERSION.SDK_INT >= 11) 
      invalidateOptionsMenu(); // Rebuild the menu 

     setTitle(project.getTitle()); 

     LinearLayout overlay = (LinearLayout) findViewById(R.id.projectview_description_overlay); 
     overlay.getBackground().setAlpha(127); 

     if(project.getProject().getPictures().size() > 0) { 
      ImageView image = (ImageView) findViewById(R.id.projectview_description_image); 
      image.setImageBitmap(project.getProject().getPictures().get(0).getImageBitmap()); 
     } 

     TextView title = (TextView) findViewById(R.id.projectview_description_title); 
     title.setText(project.getTitle()); 

     TextView baseline = (TextView) findViewById(R.id.projectview_description_baseline); 
     baseline.setText(project.getBaseline()); 

     TextView website = (TextView) findViewById(R.id.projectview_description_website); 
     if("".equals(project.getProject().getWebsite())) 
      website.setVisibility(View.GONE); 
     else 
      website.setOnClickListener(this); 

     if("".equals(project.getAboutSection())) { 
      LinearLayout aboutContainer = (LinearLayout) findViewById(R.id.projectview_description_about_container); 
      aboutContainer.setVisibility(View.GONE); 
     } else { 
      TextView aboutText = (TextView) findViewById(R.id.projectview_description_about_text); 
      aboutText.setText(project.getAboutSection()); 
     } 

     LinearLayout questions = (LinearLayout) findViewById(R.id.projectview_description_questions_container); 
     for(Question question : project.getProject().getQuestions()) { 
      if(question.getAnswer() != null) { 
       LinearLayout questionLayout = (LinearLayout) getLayoutInflater().inflate(R.layout.projectview_question, null); 

       TextView questionView = (TextView) questionLayout.findViewById(R.id.projectview_question_question); 
       TextView answerView = (TextView) questionLayout.findViewById(R.id.projectview_question_answer); 

       questionView.setText(question.getQuestion()); 
       answerView.setText(question.getAnswer().trim()); 

       questions.addView(questionLayout); 
      } 
     } 
    } 

    public void onClick(View arg0) { 
     Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(project.getProject().getWebsite())); 
     startActivity(intent); 
    } 
} 

मदद के लिए धन्यवाद!

उत्तर

8

यह ढांचे के कैशिंग तंत्र में एक बग के कारण है। सबसे आसान कामकाज एक रंग का उपयोग करना है जो लगभग काला है, जैसे कि #ff010101

+0

इसके लिए उचित समाधान क्या है? या मैं कहूंगा कि इसके लिए कोई उचित समाधान है? और क्या Google बग ट्रैकर पर कुछ है? –

0

लेआउट के प्रत्येक उदाहरण पर काले रंग की विशेषता को परिभाषित करने के बजाय, क्या आपने उस विशेषता के साथ एक कस्टम शैली सेट करने का प्रयास किया है? एक ओर, यह रखरखाव के लिए बेहतर है, लेकिन दूसरी तरफ, स्टाइलिंग इंजन कॉन्फ़िगरेशन परिवर्तनों के साथ बेहतर व्यवहार करता है और समस्या हल हो जाएगी।

+0

मैंने [शैली बनाने] [http://paste.keuse.fr/view/75698231.html) करने की कोशिश की है, लेकिन यह काम नहीं करता है, काले रंग की पृष्ठभूमि अभी भी भूरे रंग में जा रही है (जैसा कि आप देख सकते हैं स्क्रीनशॉट पर पहली पोस्ट में जोड़ा गया)। मदद के लिए धन्यवाद :) – Kyriog

संबंधित मुद्दे