Search code examples
androidandroid-layoutandroid-viewtablerowandroid-tablelayout

Some parts of TextViews don't show and are cut off by the edge of the screen


enter image description here

I have a query results from a database and corresponding variables are filled. I think that the problem is the layout, I am using incorrect layouts in my XML file. Maybe it is the ArrayAdapter, I don't know. I've spent a lot of hours trying to solve this problem and haven't been able to. Thanks for your help!

This is my XML:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<TableRow>        
    <TextView android:id="@+id/precio_offers_charger"            
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:textStyle="bold"
        android:textSize="20px"     
        android:textColor="#FFFFFF"        
        android:background="#FF0000" />

    <TextView android:id="@+id/cabecera_offers_charger"
        android:paddingLeft="10px"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textStyle="bold"
        android:textSize="18px"
        android:textColor="#FFFFFF"
        android:background="#010201" />                 
</TableRow>  

<TableRow>
    <ImageView android:id="@+id/imagen"        
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView android:id="@+id/descripcion_offers_charger"
        android:paddingLeft="10px"
        android:paddingTop="10px"           
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:textStyle="normal"
        android:textSize="14px" />                                      
</TableRow>     

<ListView android:id="@android:id/list"        
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >
</ListView>

</TableLayout>

This is a part of my class:

public class OffersChargerActivity extends ListActivity{                    

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);     
    setContentView(R.layout.offers_charger);

... 


public class AdaptadorTitulares extends ArrayAdapter<Oferta> {

    Activity context;

    AdaptadorTitulares(Activity context) {
        super(context, R.layout.offers_charger, ofertas);
        this.context = context;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = convertView;
        if (view == null) {
            LayoutInflater linflater = (LayoutInflater)   getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = linflater.inflate(R.layout.offers_charger, null);
        }                   

        // poblamos la lista de elementos           
        TextView precio = (TextView)view.findViewById(R.id.precio_offers_charger);
        precio.setText(ofertas.get(position).getPrecio().concat("€"));

        ImageView imagen = (ImageView) view.findViewById(R.id.imagen);
        imagen.setImageBitmap(new GetImages().downloadFile(ofertas.get(position).getImagen()));

        TextView cabecera = (TextView)view.findViewById(R.id.cabecera_offers_charger);
        cabecera.setText(ofertas.get(position).getCabecera());

        TextView descripcion = (TextView)view.findViewById(R.id.descripcion_offers_charger);
        descripcion.setText(ofertas.get(position).getDescripcion());                                                

        return view;
    }                       
}   

...

}


Solution

  • This worked for me:

       <TextView
            android:id="@+id/nameText"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center_vertical"
            android:textColor="@android:color/black" />
    

    Try adding in 'layout_weight' and change your 'layout_width' to "fill_parent".

    Hope this helps!