Android View未显示

时间:2014-08-16 12:06:04

标签: android android-layout android-activity

不显示观看次数, 上面的topselection视图包含两个视图。 下面的方法称那个时间内容不像textview那样显示 和图像视图,事件文本和图像分配正确。

public void updateview()
    {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(adapterContext);
        draggableGrid.removeAllViews();
        dragArray.clear();
        LayoutInflater inflater = (LayoutInflater) adapterContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        for(int index = 0;index<pData.picturelist.size();index++)
        {   
            ViewGroup view = (ViewGroup) inflater.inflate(R.layout.topselectionview, null);
            //buttons do not work with draggable grid view hence text view is used
            TextView i = (TextView)view.findViewById(R.id.text);
            ImageView img = (ImageView)view.findViewById(R.id.selectionImage);

            //i = new TextView(adapterContext);  

            i.setPadding(5, pData.topPadding, 5, (int) (pData.columnheight*0.056f));

            i.layout(0, 0, 0, 0);   


            //set the text properties for the image tag
            i.setTextAppearance(adapterContext, R.style.imageTag);

            i.setGravity(Gravity.CENTER|Gravity.BOTTOM);

            if(cutrecordid!=null)
                if(cutrecordid.equals(pData.picturelist.get(index).cid))
                    continue;
            //get the path of the image
            String image = pData.picturelist.get(index).imagePath;
            String pp="";
            if(image.contains("custom_images")){
                pp = AvazAppActivity.avazRootDir+"/avaz/" + image;
            }else{
                if(AvazAppActivity.isValidImage(image)){
                    if(image.startsWith("ci_"))
                        pp = AvazAppActivity.avazRootDir+"/avaz/user1/custom_images/" + image;
                    else
                        pp = AvazAppActivity.avazRootDir+"/avaz/png/" + image;
                }               
            }
            bitmapImage = AvazAppActivity.loadIm.readBitmapFromSDCard(pp);

            //get the bitmap of the image
            Drawable bgrImage = new BitmapDrawable(bitmapImage);

            if(bitmapImage != null)
            {
                int drawablepadding=0;
                int ch=(pData.columnwidth*(pData.imgPercent))/100;
                int cw=(pData.columnwidth*(pData.imgPercent))/100;
                try{
                    int h1=(cw*bgrImage.getIntrinsicHeight())/bgrImage.getIntrinsicWidth();
                    int w1=(ch*bgrImage.getIntrinsicWidth())/bgrImage.getIntrinsicHeight();
                    if(h1>ch)
                        h1=ch;
                    else if(w1>cw)
                        w1=cw;
                    int pad=0;
                    if(ch>h1){
                        pad=(ch-h1)/2;
                    }
                    drawablepadding=pad;
                    bgrImage.setBounds( 0, pad, w1, pad+h1 );
                }catch(ArithmeticException e){
                    e.printStackTrace();
                }

                i.setCompoundDrawables(null, bgrImage, null, null);

                i.setCompoundDrawablePadding(drawablepadding);
                try {
                    OverlayScreen.class.getDeclaredMethod("setPictureFontStyle",new Class[]{View.class,Integer.class}).invoke(adapterContext, i,pData.txtSize);
                }catch (Exception e) {
                    e.printStackTrace();
                }
            }
            else{
                try {
                    OverlayScreen.class.getDeclaredMethod("setPictureFontStyle",new Class[]{View.class,Integer.class}).invoke(adapterContext, i,(int)(pData.txtSize + pData.txtSize*0.5));
                }catch (Exception e) {
                    e.printStackTrace();
                }

            }
            i.setText(getTruncateText(pData.picturelist.get(index).templateName,i));
            //set the tag of the text view to identify the view when clicked
            i.setTag(pData.picturelist.get(index));

            i.setGravity(Gravity.BOTTOM|Gravity.CENTER);

            if(pData.picturelist.get(index).enabled == true)
            {
                //draw the category of template in the enabled state
                if(pData.picturelist.get(index).type.equalsIgnoreCase("D"))
                    i.setBackgroundDrawable(adapterContext.getResources().getDrawable(ColorManager.getCatBGIdWithoutEffect(pData.picturelist.get(index).color,prefs.getString("colorcode", "solid"))));
                else
                    i.setBackgroundDrawable(adapterContext.getResources().getDrawable(ColorManager.getTempBGIdWithoutEffect(pData.picturelist.get(index).color,prefs.getString("colorcode", "solid"))));
            }
            else
            {
                //draw the category of template in the disabled state
                if(pData.picturelist.get(index).type.equalsIgnoreCase("D"))
                    i.setBackgroundDrawable(adapterContext.getResources().getDrawable(R.drawable.disablefolder));
                else
                    i.setBackgroundDrawable(adapterContext.getResources().getDrawable(R.drawable.disabletemplate));
            }      

            i.setHeight(i.getBackground().getBounds().height());
            i.setWidth(i.getBackground().getBounds().width());   

            //add the text view to the grid and to array 
            draggableGrid.addView(view);
            dragArray.add(view);      

        } 
    }

以下是包含元素的xml文件。

topselectionview.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="#000000" >
    <TextView
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
    <ImageView
        android:id="@+id/selectionImage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/correct_highlighted"
        android:layout_alignParentRight="true"/>
</RelativeLayout>

1 个答案:

答案 0 :(得分:0)

这不是问题的答案,但我只是想让你知道

  • 只需备注 :: setBackgroundDrawable - &gt; View.setBackgroundDrawable(Drawable background)
  • 此方法已在API level 16中弃用。使用 setBackground(Drawable)而不是

<强>来源:Developer Docs