Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>Each element of the Gallery consists on a <code>LinearLayout</code></p> </blockquote> <p>Just wrap it using another <code>LinearLayout</code> and set the margin in the <code>LinerLayout.LayoutParams</code> for the inner <code>LinearLayout</code>. I have checked it, and it seems to do what you want.</p> <p>So the layout you inflate for Gallery item should look like this:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/layOuter" android:layout_width="wrap_content" android:layout_height="wrap_content"&gt; &lt;LinearLayout android:id="@+id/layInner" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical"&gt; &lt;ImageView android:id="@+id/imageView1" android:src="@drawable/icon" android:layout_height="wrap_content" android:layout_width="wrap_content" android:scaleType="fitXY" /&gt; &lt;TextView android:text="TextView" android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:visibility="visible" /&gt; &lt;/LinearLayout&gt; &lt;/LinearLayout&gt; </code></pre> <p>Then you can access inner LinearLayout in adapter <code>getView</code> method and set margin there depending on your conditions (sample code without convertView reuse optimization):</p> <pre><code>public View getView(int position, View convertView, ViewGroup parent) { Context context = getContext(); final float density = context.getResources().getDisplayMetrics().density; LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View layOuter = inflater.inflate(R.layout.row_layout, null); View layInner = layOuter.findViewById(R.id.layInner); if (...) { // your condition LinearLayout.LayoutParams innerLP = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); innerLP.leftMargin = (int) (50 * density); layInner.setLayoutParams(innerLP); } return layOuter; } </code></pre> <p>Please note that you must use <code>LinearLayout.LayoutParams</code> (it extends <code>MarginLayoutParams</code>) for the inner layout, otherwise it will not work. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload