2012-03-17 40 views
0

我试图执行的想法是打印一个吉他指板,并在其上方一些方块指出一些笔记。那么,一张图片胜过千言万语,所以this is it运行在Android 2.3.3上布局API依赖?

“为什么你需要我们的帮助,所以呢?!”因为我试着在Android 4.0.3中运行它,结果是this other one。我意识到(只留下一个正方形)正方形试图尽可能大,所以我为每个点添加了dot [counter] .setScaleType(ScaleType.CENTER)并获取了这个(http://i.imgur。对不起,我不能发布另一个超链接),而2.3.3仍然是第一次捕获相同。这使我无法普遍地将setPadding()设置为每个点,因为它在两个版本中不同。不得不说,它完全是相同的代码,只是在不同的AVD中运行(我也尝试了具有相同结果的物理设备)。

我也尝试在代码和xml中更改布局的引力,但没有任何效果。

我在复制我认为与情况有关的内容,但随时可以要求其他任何内容。

这是我简单的布局:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/RelativeLayout1" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:gravity="top" 
android:orientation="vertical" > 

<TextView 
    android:id="@+id/textView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_centerHorizontal="true" 
    android:text="@string/add" 
    android:textAppearance="?android:attr/textAppearanceLarge" /> 


<FrameLayout 
    android:id="@+id/layoutFrets" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_centerHorizontal="true" > 

    <ImageView 
     android:id="@+id/imageView1" 
     android:scaleType="fitXY" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/fretboard" /> 

</FrameLayout> 

这里是生成和活动的代码打印点:

要创建ImageViews:

for (int i = 0; i<notesN; i++) 
     dot[i] = new ImageView(this); 

要打印它们,我必须这样做,因为我需要打印布局的大小点OK

fl.post(new Runnable(){ 
     public void run() { 
      int counter = 0; 

      //Pointless constants go here to print the dots in their place    

      for (int strings = 0; strings < fretboard.NSTRINGS; strings++){ 
       for (int frets = 0; frets < fretboard.NFRETS; frets++){ 

        if (fretboard.isOccupied(strings, frets)){ 
         dot[counter].setScaleType(ScaleType.CENTER); 
         dot[counter].setImageResource(R.drawable.dot); 

         //Quite a messy code... calculates the positions based 
         //on the constants above 
         dot[counter].setPadding(
           (int) (-fl.getWidth() + 2 * fl.getWidth() 
             * fretDistance[frets]), 
           (int) (fl.getHeight() * (stringDistance[strings])), 
           0, 0); 

         fl.addView(dot[counter]); 
         counter++; 
        } 
       } 
      } 

     } 

    }); 

这将解决我给你的最后一次捕获。

我也尝试在post()方法之外初始化ImageView,结果相同。

任何想法我做错了什么?非常感谢你提前:) :)

回答

0

我醒来的想法,改变布局的类型......它的工作。

更改了FrameLayout的相对布局,一切按预期工作。

我仍会密切关注此线索,以便有人可以对发生的原因作出解释。