If I create a custom layout for a list view row and in the root view of that layout I specify a margin for example:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="15dp">
<!— some cool row stuff (other view components that makeup your row) —>
</RelativeLayout>
Then the 15dp margin will be ignored. I could fix this by simply doing this:
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="15dp">
<!— some cool row stuff (other view components that makeup your row) —>
</RelativeLayout>
</FrameLayout>
But that adds another layout... which I have been discouraged from doing. People say its a bad practice to just add layouts when one layout can do the job. Is this the correct/ok way to do this or does any one else know another way to solve this?
Thanks
Note: Also there is a similar question here that asks why the margin does not work. There is no answer on that question for what is the correct solution but a good explanation for why. The question was not how to fix but why so I thought a new question was appropriate.
similar question: Why LinearLayout's margin is being ignored if used as ListView row view