How to leave space between images?

3

I have this layout:

telainicial.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:id="@+id/ad_linear_layout" xmlns:ads="http://schemas.android.com/apk/res-auto" tools:context="praias.android.makerapp.com.praias.TelaInicial" android:background="#ffffff"> <ScrollView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/scrollView" android:layout_above="@+id/adView"> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent" > <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginRight="5dp" android:layout_marginTop="5dp" android:layout_weight="1" android:gravity="start" android:id="@+id/l1" android:layout_alignParentTop="true"></LinearLayout> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginRight="7dp" android:layout_marginTop="5dp" android:layout_weight="1" android:gravity="start" android:id="@+id/l2" android:layout_alignParentTop="true"></LinearLayout> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="5dp" android:layout_weight="1" android:gravity="start" android:id="@+id/l3" android:layout_alignParentTop="true"></LinearLayout> </LinearLayout> </ScrollView>

Here in java I create the imageview and textview and hedge every linearlayout telainicial.java

            if(l==1){
                layout1.addView(btCategoria);
                layout1.addView(txtCategoria);

                l=2;
            }else if(l==2){
                layout2.addView(btCategoria);
                layout2.addView(txtCategoria);

                l=3;
            }else if(l==3){
                layout3.addView(btCategoria);
                layout3.addView(txtCategoria);

                l=1;
            }

I used android:layout_marginRight="7dp" to leave a space between the side images. There, I was wanting to leave a space down for the textiew not to get too stuck the image. I tried to use android:layout_marginTop="5dp" and also android:layout_marginBottom="5dp" to move away a bit, but neither worked.

Note: I did not use a gridview because what I found did not work for my api

Creating buttons

TextView txtCategoria = (TextView)LayoutInflater.from(this).inflate(R.layout.text, null);

            final ImageButton btCategoria = (ImageButton) LayoutInflater.from(this).inflate(R.layout.button, null);
            btCategoria.setId((int) listenerCategoria.id);

Layout declaration

layout1 = (LinearLayout) findViewById(R.id.l1);
    layout2 = (LinearLayout) findViewById(R.id.l2);
    layout3 = (LinearLayout) findViewById(R.id.l3);

Resolution

txtCategory.setPadding (0,0,0,10);

I put a serPadding in the textview and put the bottum in 10

    
asked by anonymous 16.04.2015 / 21:47

1 answer

3

Just as these two views were created programmatically, you can also define the margin values as follows:

LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
llp.setMargins(0, 0, 0, 50);
txtCategoria.setLayoutParams(llp);

In this example the value of the lower margin of the TextView is defined, so the next inclusion of ImageView within this layout will have this space above.

    
16.04.2015 / 22:25