Android : Android put a view on bottom of screen in code

on Saturday, September 6, 2014


I have two viewa that are loaded in code. I want to put a button in the bottom of the linearlayout container but is shown directly in the bottom of the first tableView elements, added in code.


The code that of LinearLayout that will contains all of the elements:



<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.app.easylist.ScreenPrincipalList"
android:gravity="center_horizontal"
android:orientation="vertical"
android:id="@+id/container"
android:background="@color/green" >


the code of linear layout of the elements that are loaded as a 3x3 table



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/categoriacontainer" >

<ImageButton
android:id="@+id/imgCate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="center"
android:src="@drawable/ic_launcher"
android:contentDescription="@string/imgbuttoncat"
android:longClickable="true" />

<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:ellipsize="end"
android:singleLine="true"
android:gravity="center"
android:id="@+id/txtcategoriatext" />

</LinearLayout>


The xml code of the button that I desire to shown in the bottom of the screen, not in the bottom of the tableLayout added in code:



<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/linnewcat"
android:background="@color/red" >
<Button
android:id="@+id/btnnewcentre"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/txtnewlist"
android:background="@drawable/btn_dsg_principal"
android:layout_margin="5dip">
</Button>


And the code that load all of the elements:



listEle= new ProbList().getListEle();

LinearLayout container = (LinearLayout)findViewById(R.id.container);
TableLayout tableContainer = new TableLayout(this);

int i = 0;

TableRow tr = new TableRow(this);

while( i < listEle.size()){

View layout = getLayoutInflater().inflate(R.layout.categoriadesign, null);

tr.addView(layout);

TextView txtCat = (TextView)layout.findViewById(R.id.txtcategoriatext);
txtCat.setText(listEle.get(i).getNomLlista());
Bitmap resizedbitmap = ImagesResources.getInstance()
.StringResourceToBitmapResized(getResources(),
getPackageName(), listEle.get(i).getSrcImatge(),
200, 200, true);
ImageButton imgBut = (ImageButton)layout.findViewById(R.id.imgCate);
imgBut.setImageBitmap(resizedbitmap);
ArrayList<Variables> passvar = new ArrayList<Variables>();
passvar.add(new Variables("id",String.valueOf(i)));
imgBut.setOnClickListener(new CustomOnclickListener(passvar, ScreenGestLlista.class, getApplicationContext()));
imgBut.setOnLongClickListener(new View.OnLongClickListener() {

@Override
public boolean onLongClick(View v) {
// TODO Auto-generated method stub
return false;
}
});
i++;
if ((i % 3) == 0){
tableContainer.addView(tr);
tr = new TableRow(this);
}else if(i == llista.size() ){
tableContainer.addView(tr);
}
}
container.addView(tableContainer);

View linbottom = getLayoutInflater().inflate(R.layout.linbtnbottomprincipal, null);
RelativeLayout.LayoutParams position = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
position.addRule(RelativeLayout.ALIGN_BOTTOM);
container.addView(linbottom,position);


Thanks


0 comments:

Post a Comment