开发者

getview in listadapter

In my listadapter code, I would like to indent my view. To do that i add some left padding but that doesnt seem to work.

EDIT: main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    a开发者_StackOverflow中文版ndroid:layout_width="fill_parent" android:layout_height="fill_parent">
    <LinearLayout  
        android:layout_width="80dip" android:layout_height="fill_parent"
        android:gravity="right|center_vertical">
        <ImageView android:id="@+id/item_image" android:layout_width="wrap_content"
         android:src="@drawable/icon" android:layout_height="wrap_content"></ImageView>
    </LinearLayout>
    <FrameLayout android:id="@+id/frame"
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        android:layout_weight="1" >
    </FrameLayout>
</LinearLayout>

any suggestions why padding would not work ?? I want to move the image x dp to the right.

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

            if (convertView == null) {
                final LinearLayout layout = (LinearLayout) layoutInflater.inflate( R.layout.main, null); 
                layout.setPadding(100, 8,8,8);


                return layout;
            } else {
//do stuff   
        }
    }

thanks


try this code

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


                final View layout = View.inflate(context, R.layout.main, null); 
                layout.setPadding(100, 8,8,8);


                return layout;

    }


You are taking the reference of a xml file ..... you should get reference to the layout defined in xml file or any other view of xml file to set params ......

You can set param on the view not on xml file....


If setting padding does not work, you could always try:

layout.offsetLeftAndRight(100);


I guess .. you can give padding in your xml layout using android:padding...... (left or right or top or bottom) . Specifying them in xml layout file will indent the ImageView as per requirements.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜