2013-08-23 62 views
0

問題:列表視圖僅在高分辨率的設備沒有出現在最右邊角的圖像

應該在ListView顯示佈局簡單應用,佈局包含這樣的數據:

ImageView的1 ---文本視圖1 /(下文)文本查看2 ---圖像查看2

問題是圖像查看2在像銀河S4和大二重奏一些設備不可見

工作:

enter image description here

不工作:

enter image description here

代碼:

項目結構:

enter image description here

MainActivity代碼:

package com.example.screenfix; 

import java.util.ArrayList; 
import java.util.HashMap; 

import android.app.Activity; 
import android.os.Bundle; 
import android.view.Menu; 
import android.widget.ListView; 

public class MainActivity extends Activity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     ArrayList<HashMap<String, String>> songsList = new ArrayList<HashMap<String, String>>(); 

     HashMap<String, String> map = new HashMap<String, String>(); 
     map.put("App_Name", "Test Data"); 
     map.put("App_Desc", "Test Description"); 
     map.put("Price", "free"); 
     map.put("image_url","importicon"); 
     songsList.add(map); 

     BinderData bindingData = new BinderData(this,songsList); 
     ListView list = (ListView) findViewById(R.id.listView1); 

     list.setAdapter(bindingData); 
    } 

    @Override 
    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; 
    } 

} 

AdapterCode:

package com.example.screenfix; 

import java.util.HashMap; 
import java.util.List; 

import android.app.Activity; 
import android.content.Context; 
import android.graphics.drawable.Drawable; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.BaseAdapter; 
import android.widget.ImageView; 
import android.widget.TextView; 

public class BinderData extends BaseAdapter { 

    // XML node keys 
    static final String KEY_TAG = "weatherdata"; // parent node 
    static final String KEY_ID = "id"; 
    static final String KEY_CITY = "city"; 
    static final String KEY_TEMP_C = "tempc"; 
    static final String KEY_TEMP_F = "tempf"; 
    static final String KEY_CONDN = "condition"; 
    static final String KEY_SPEED = "windspeed"; 
    static final String KEY_ICON = "icon"; 

    LayoutInflater inflater; 
    ImageView thumb_image; 
    List<HashMap<String,String>> weatherDataCollection; 
    ViewHolder holder; 
    public BinderData() { 
     // TODO Auto-generated constructor stub 
    } 

    public BinderData(Activity act, List<HashMap<String,String>> map) { 

     this.weatherDataCollection = map; 

     inflater = (LayoutInflater) act 
       .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    } 


    public int getCount() { 
     // TODO Auto-generated method stub 
//  return idlist.size(); 
     return weatherDataCollection.size(); 
    } 

    public Object getItem(int arg0) { 
     // TODO Auto-generated method stub 
     return arg0; 
    } 

    public long getItemId(int position) { 
     // TODO Auto-generated method stub 
     return 0; 
    } 

    public View getView(int position, View convertView, ViewGroup parent) { 

     View vi=convertView; 
     if(convertView==null){ 

      vi = inflater.inflate(R.layout.rowdata, null); 
      holder = new ViewHolder(); 

      holder.tvCity = (TextView)vi.findViewById(R.id.textView1); // city name 
      holder.tvWeather = (TextView)vi.findViewById(R.id.textView2); // city weather overview 
      holder.tvTemperature = (ImageView)vi.findViewById(R.id.imageView2); // city temperature 
      holder.tvWeatherImage =(ImageView)vi.findViewById(R.id.imageView1); // thumb image 

      vi.setTag(holder); 
     } 
     else{ 

      holder = (ViewHolder)vi.getTag(); 
     } 

      // Setting all values in listview 

      holder.tvCity.setText(weatherDataCollection.get(position).get("App_Name")); 
      holder.tvWeather.setText(weatherDataCollection.get(position).get("App_Desc")); 
      String uri = ""; 
      if(weatherDataCollection.get(position).get("Price").equalsIgnoreCase("pro")) 
      { 
       uri = "drawable/label"; 

      }else{ 
       uri = "drawable/free"; 
      } 
      int imageResource = vi.getContext().getApplicationContext().getResources().getIdentifier(uri, null, vi.getContext().getApplicationContext().getPackageName()); 
      Drawable image = vi.getContext().getResources().getDrawable(imageResource); 
      holder.tvTemperature.setImageDrawable(image); 
      //holder.tvTemperature.setText(weatherDataCollection.get(position).get("Price")); 

      //Setting an image 
      String uri2 = "drawable/"+ weatherDataCollection.get(position).get("image_url"); 
      int imageResource2 = vi.getContext().getApplicationContext().getResources().getIdentifier(uri2, null, vi.getContext().getApplicationContext().getPackageName()); 
      Drawable image2 = vi.getContext().getResources().getDrawable(imageResource2); 
      holder.tvWeatherImage.setImageDrawable(image2); 

      return vi; 
    } 

    /* 
    * 
    * */ 
    static class ViewHolder{ 

     TextView tvCity; 
     ImageView tvTemperature; 
     TextView tvWeather; 
     ImageView tvWeatherImage; 
    } 

} 

MainActivity XML:

<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" 
    tools:context=".MainActivity" > 

    <ListView 
     android:id="@+id/listView1" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_centerHorizontal="true" > 

    </ListView> 

</RelativeLayout> 

ListRowData:

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

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="0dp" 
     android:layout_height="44dp" 
     android:layout_weight="0.20" 
     android:scaleType="fitStart" 
     android:src="@drawable/importicon" /> 

    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_weight="0.70" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" > 

     <TextView 
      android:id="@+id/textView1" 
      android:layout_width="wrap_content" 

      android:layout_height="wrap_content" 
      android:text="TextView 1" /> 

     <TextView 
      android:id="@+id/textView2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="TextView 2" /> 
    </LinearLayout> 

    <ImageView 
     android:id="@+id/imageView2" 
     android:layout_width="0dp" 
     android:layout_height="50dp" 
     android:layout_weight="0.10" 

     android:src="@drawable/free" /> 

</LinearLayout> 

任何幫助理解...

+0

把圖標放入'Drawable-hdpi'並嘗試.... – NagarjunaReddy

回答

0

申請android:layout_width="match_parent"和rowdata.xml改變android:layout_weight=""(如下所示),以兩者的ImageView和內部的LinearLayout

這裏是代碼

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

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="match_parent" 
     android:layout_height="44dp" 
     android:layout_weight="2" 
     android:scaleType="fitStart" 
     android:src="@drawable/ic_launcher" /> 

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

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="TextView 1" /> 

    <TextView 
     android:id="@+id/textView2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="TextView 2" /> 
    </LinearLayout> 

    <ImageView 
    android:id="@+id/imageView2" 
    android:layout_width="match_parent" 
    android:layout_height="50dp" 
    android:layout_weight="2" 
    android:src="@drawable/ic_launcher" /> 

</LinearLayout> 
0

解決:

問題是最右邊的圖標,它具有非常高的分辨率,只是降低了分辨率,取而代之的是文件,它的工作。

感謝每一個他們的時間..

相關問題