2013-05-15 4 views
0

У меня есть следующая компоновка, я хочу установить маржу программно. В этом макете я просматриваю этот макет в baseadpter. Как я могу получить к нему доступ.Как настроить маргинальность в макете, которая существует в другом макете

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" > 



    <LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    > 

    <CheckBox 
    android:layout_width="20dp" 
    android:layout_height="17dp" 
    android:button="@drawable/my_custom_checkbox" 
    android:id="@+id/check" 
    android:layout_marginTop="5dip" 
    android:checked="false" 
    > 
    </CheckBox> 

    <RelativeLayout 
     android:id="@+id/Relative" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="10dip" 
     android:layout_marginRight="6dip" 
     android:layout_weight="0.5"> 

     <TextView android:id="@+id/list_item_entry_title" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:singleLine="true" 
      android:layout_marginTop="5dip" 
      android:layout_marginBottom="15dip" 
      android:ellipsize="marquee" 
      android:text="Hello" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:fadingEdge="horizontal" /> 

    //Want to access this layout  
     <LinearLayout 
     android:id="@+id/LinearCal" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"  
     android:orientation="horizontal" 
     android:layout_marginTop="50dip" to 100dip 

ответ

1

здесь ваш код ..

LinearLayout ll = (LinearLayout) findViewbyid(R.id.LinearCal); 

    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
      RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); 

    layoutParams.setMargins(0, 100, 0, 0);//set margin left, top, right, bottom 

ll.setLayoutParams(layoutParams); 
+0

можем ли мы направить этот макет ?? – UnderGround

+0

java.lang.ClassCastException: android.widget.LinearLayout $ LayoutParams нельзя отбрасывать в android.widget.RelativeLayout $ LayoutParams. Получение этой ошибки. – UnderGround

+0

hmm, извините, мой плохой. Параметры макета должны быть установлены относительно родительского макета .. в вашем случае его относительный макет .. так обновлено сообщение plz check – CRUSADER

1

Попробуйте этот путь.

//LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); 
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); 
layoutParams.setMargins(50, 10, 0, 0); 

LinearLayout layout = (LinearLayout)findViewById(R.id.LinearCal); 
layout.setLayoutParams(layoutParams); 
+0

java.lang.ClassCastException: android.widget.LinearLayout $ LayoutParams не может be cast to android.widget.RelativeLayout $ LayoutParams. Получение этой ошибки – UnderGround

+0

Либо исправьте свой импорт, либо получите подходящие макеты Layoutparams. i.e RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams (и т. д.) – Kuffs

+0

См. мои обновления. Попробуйте этот путь. И дайте мне знать, что это либо работает, либо нет? – Gunaseelan

Смежные вопросы