Reputation: 397
I want to set the margin of the layout in adapter when I call list view. my condition is, when image set in my layout then the text margin is 15dp and when my image visibility gone then text margin will be 180 dp,how is it possible? can i do this work in xml? if yes then reply me.
Upvotes: 2
Views: 1252
Reputation: 397
view_holder._feedImage.setVisibility(View.GONE);
RelativeLayout.LayoutParams par=new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
par.addRule(RelativeLayout.BELOW, R.id.feed_text);
par.setMargins(60,10, 0, 0);
view_holder._linear.setLayoutParams(par);
RelativeLayout.LayoutParams par1=new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
par1.addRule(RelativeLayout.BELOW, R.id.linearLayout1);
par1.setMargins(10,10, 0, 0);
view_holder._linear_ll.setLayoutParams(par1);
Upvotes: 0
Reputation: 1701
In the xml of your layout, set the property to your ListView:
android:layout_margin="15dp"
This will set a margin top/bottom etc.
If you want, you can specify using: android:layout_marginTop
or android:layout_margin_Right
(for instance)
--Edited-- From XML:
LinearLayout ll = (LinearLayout) getLayoutInflater().inflate(R.layout.yourLinearLayoutFileId, null);
In your xml file:
<LinearLayout xmlns ="..."
android:id="@+id/ll"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:margin = "15dp"
.....
>
....
Upvotes: 2