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 the textview and Seto at each 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 the android:layout_marginRight="7dp"
to leave a space between the images aside. There, I was wanting to leave a space underneath for the textiew not to get too glued to the image. I tried to use the android:layout_marginTop="5dp"
and also the android:layout_marginBottom="5dp"
to distance a little, but neither of the two worked.
Note: I didn’t use a gridview because what I found didn’t work for my api
Creation of 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 statement
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);
put a serPadding on the textviewe put the bottum at 10
These views
btCategoria
andtxtCategoria
are created programmatically, without any XML?– Paulo Rodrigues
yes , are created in cidigo , more I think I already know why I’m not able to leave a space with the
android:layout_marginBottom="5dp"
, because all images and textview are within the same layout and I’m putting it in the layout so it would only work if I had a layout below, have as I set thislayout_bottom
in java?– Ilgner de Oliveira