我試圖執行的想法是打印一個吉他指板,並在其上方一些方塊指出一些筆記。那麼,一張圖片勝過千言萬語,所以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,結果相同。
任何想法我做錯了什麼?非常感謝你提前:) :)