블로그 이미지
JoyfulLife

공지사항

최근에 받은 트랙백

글 보관함

calendar

    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    

Drag and drop in Android

2010.11.05 16:01 | Posted by JoyfulLife

There is a source that someone made using music source in Android platform.

http://www.kandroid.org/board/board.php?board=sourcecode&command=body&no=34

But it's not perfect.

abd



You can see this when you run the source.





When you click the 1's item, and moving to bottom, you 're going to notice the problem.
Did you see the problem?
I don't like 1's item between 0's and 2's.
I wanted 2's item to be bottom.

So, I looked the source. At the first time, I think the source maker made a mistake. So I tried to find source error.
But source was perfect. I compared this source with Android music source, There were no problem.








finally, I got the problem.
problem was gravity.

when you see DndSampleActivity.java
there are

mAdapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, data);

in OnCreate().

R.layout.simple_list_item_1 is

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/text1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:gravity="center_vertical"
    android:paddingLeft="6dip"
    android:minHeight="?android:attr/listPreferredItemHeight"
/>


android:gravity="center_vertical" is not good match at this point.

center_vertical make text to be center. I want text to be bottom.

So I make the row.xml in the layout.

R.layout.row.xml is

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/text1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:paddingLeft="6dip"
    android:minHeight="?android:attr/listPreferredItemHeight" android:gravity="bottom|center_vertical"/>

and 
mAdapter = new ArrayAdapter<String>(this,
                R.layout.row, data);

I added bottom to the gravity.



Now, you can see the item that is right place.

신고

티스토리 툴바