簡體   English   中英

listadapter中的getview

[英]getview in listadapter

在我的listadapter代碼中,我想縮進我的觀點。 要做到這一點,我添加一些左邊填充,但似乎不起作用。

編輯:main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android: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>

任何建議為什么填充不起作用? 我想將圖像x dp向右移動。

 @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   
        }
    }

謝謝

試試這段代碼

@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;

    }

您正在參考xml文件.....你應該參考xml文件中定義的布局或xml文件的任何其他視圖來設置params ......

您可以在視圖上設置param,而不是在xml文件上....

如果設置填充不起作用,您可以嘗試:

layout.offsetLeftAndRight(100);

我想..你可以使用android:padding ......(左或右或頂部或底部)在你的xml布局中給出填充。 在xml布局文件中指定它們將根據要求縮進ImageView。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM