2011-08-09 54 views
0

在我的listadapter代碼中,我想縮進我的視圖。要做到這一點,我添加一些左填充,但似乎沒有工作。getview in 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 
     } 
    } 

感謝

+0

你的main.xml文件裏面有什麼?你知道填充不會改變位置,也不會改變它所應用的「盒子」的大小,不是嗎?它僅適用於「內部邊距」,因此只有在main.xml包含其他視圖時纔會顯示。 – darma

+0

沒有你的佈局文件,我們將無法幫你 – Janusz

回答

0

你正在一個xml文件的引用.....你應該參考XML文件或XML文件中設置則params的任何其他視圖中定義的佈局? ...

您可以在視圖不是XML文件中設置PARAM ....

+0

他膨脹了xml文件的佈局,似乎對我來說或多或少是正確的 – Janusz

+0

@Janusz這種方式一次不適用於我,它是參考問題... –

2

試試這個代碼

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

    } 
0

如果設置填充不工作,你總是可以嘗試:

layout.offsetLeftAndRight(100); 
0

我想..你可以使用Android在你的XML佈局給填充:填充......(左或右或頂部或底部)。在xml佈局文件中指定它們會根據需要縮進ImageView。

+0

我想更改行值的縮進depwnding。因此不能在xml中指定它 – jsp