1

I have this Design in Relative Layout. I have to do some more things.

  1. How can I remove that straight line between two elements ?
  2. How can I increase space between two elements ?
  3. How to display product side by side ?

I have tried several solutions from stackoverflow. Like I have used margin bottom but got no luck.

enter image description here

  <?xml version="1.0" encoding="utf-8"?>


 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="wrap_content"
 android:layout_height="250dp"
 android:background="@drawable/round_corner"
 android:layout_marginRight="20dp"
  >



<RelativeLayout
    android:layout_width="200dp"
    android:layout_height="250dp"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true"
    android:paddingRight="20dp"
    android:paddingLeft="20dp"
    >



      <de.hdodenhof.circleimageview.CircleImageView xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/product_image"
        android:layout_width="match_parent"
        android:layout_height="150dp"
        android:layout_marginLeft="15dp"
        android:layout_marginTop="20dp"
        android:foregroundGravity="center"
        app:civ_border_color="#d1b1b1"

        />


    <View
        android:layout_width="match_parent"
        android:layout_height="180dp"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_marginStart="1dp"
        android:layout_marginTop="0dp"
        android:background="@drawable/gradient" />


    <TextView
        android:id="@+id/product_name_english"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@id/product_image"
        android:layout_alignTop="@id/product_image"
        android:layout_alignRight="@id/product_image"
        android:layout_alignBottom="@id/product_image"
        android:layout_margin="1dp"
        android:gravity="center"
        android:text="Hello"
        android:textColor="#FFFF"
        android:fontFamily="@font/aerial"/>


    <TextView
        android:id="@+id/price"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/product_name_english"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="-51dp"
        android:layout_marginBottom="1dp"
        android:fontFamily="@font/aerial"
        android:text="Hello"
        android:textColor="#FFFF" />

    <Button
        android:layout_width="250dp"
        android:layout_height="20dp"
        android:layout_alignParentTop="true"
        android:layout_marginTop="194dp"
        android:background="@drawable/buttonshape"
        android:shadowColor="#A8A8A8"
        android:shadowDx="0"
        android:shadowDy="0"
        android:shadowRadius="5"
        android:text="Add to cart"
        android:textColor="#FFFFFF"
        android:textSize="10sp" />

    <Button
        android:layout_width="250dp"
        android:layout_height="20dp"
        android:layout_alignParentTop="true"
        android:layout_marginTop="224dp"
        android:background="@drawable/buttonshape"
        android:shadowColor="#A8A8A8"
        android:shadowDx="0"
        android:shadowDy="0"
        android:shadowRadius="5"
        android:text="View Product"
        android:textColor="#FFFFFF"
        android:textSize="10sp" />
   </RelativeLayout>





</FrameLayout>

Here is the listview I am sending to my Adapter

        listView = (ListView) findViewById(R.id.product_list);
        mAdapter = new all_product_list_ArrayAdapter(all_product.this,data);
        listView.setAdapter(mAdapter);

Here is my ArrayAdapter Class :

      package com.example.yunus.ybazar_android;

    import android.content.Context;
    import android.content.Intent;
     import android.graphics.drawable.Drawable;
     import android.support.annotation.LayoutRes;
    import android.support.annotation.NonNull;
   import android.support.annotation.Nullable;
    import android.util.Log;
   import android.view.LayoutInflater;
     import android.view.View;
    import android.view.ViewGroup;
   import android.widget.ArrayAdapter;
   import android.widget.Button;
   import android.widget.ImageView;
   import android.widget.TextView;
    import android.support.v7.app.AppCompatActivity;
   import android.os.Bundle;
   import android.view.View;


 import java.io.InputStream;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.List;
 import android.support.annotation.NonNull;
 import android.widget.Toast;

 import com.bumptech.glide.Glide;
 import com.bumptech.glide.load.engine.DiskCacheStrategy;

 public class all_product_list_ArrayAdapter extends   ArrayAdapter<all_product_list_android_model>  {

  private final String Tag = "Filter" ;

  private Context mContext;
  private ArrayList<all_product_list_android_model> product_list ;

  private final String urlMain = "http://118.179.70.235:28965/media/" ;




  public all_product_list_ArrayAdapter(@NonNull Context context, ArrayList<all_product_list_android_model> list) {
    super(context, 0, list);
    mContext = context ;
    product_list = list ;

}

   @NonNull
   @Override
   public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {

        View listItem = convertView;

        if(listItem == null)
             listItem = LayoutInflater.from(mContext).inflate(R.layout.all_product_list_arrayadapter_connection,parent,false);

           all_product_list_android_model   product_list_to_show = product_list.get(position);

           ImageView image = (ImageView)listItem.findViewById(R.id.product_image);
          new DownLoadImage(image).execute(urlMain.concat(product_list_to_show.product_main_image));


           TextView name = (TextView)   listItem.findViewById(R.id.product_name_english);
        name.setText(product_list_to_show.product_name_english);

        TextView price = (TextView) listItem.findViewById(R.id.price);
        price.setText(("Taka ")
                 .concat(product_list_to_show.product_unit_price)
                 .concat("/")
                 .concat(product_list_to_show.product_unit));



        final Button bt = (Button) listItem.findViewById(R.id.add_to_cart);
        bt.setTag(product_list_to_show.id);

        final Button bt2 = (Button) listItem.findViewById(R.id.view_product);
        bt2.setTag(product_list_to_show.id);




    bt.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {



        }
    });



       bt2.setOnClickListener(new View.OnClickListener() {
             public void onClick(View v) {

                Intent intent = new Intent(mContext, indi_product_show.class);
                intent.putExtra("product_id",String.valueOf(bt2.getTag()));
                mContext.startActivity(intent);

          }
      });


          return listItem;
     }


 }
Rafaela Lourenço
  • 1,126
  • 16
  • 33
Yunus
  • 405
  • 5
  • 18
  • the code is about showing 1 product, how are you showing all elements in screen? recyclerview? or static layout? – stallianz Oct 24 '18 at 16:46
  • Oh yeah sorry. I am using ArrayAdapter to show all the product. Basically I am fetching data from database then convert JsonArray to Array list and then show them in ArrayAdapter class. This is basically the layout which connects with ArrayAdapter class. – Yunus Oct 24 '18 at 16:54
  • sorry for the confusiton, ArrayAdapter is not a view, my question is, where are these hosted? – stallianz Oct 24 '18 at 16:56
  • I have edited my question. But I can not understand by the question 'where are these hosted ? ' – Yunus Oct 24 '18 at 17:14
  • ListView is old, I recommend using RecyclerView, as per your requirements there is a code snippet in here: https://stackoverflow.com/questions/3240331/horizontal-listview-in-android – stallianz Oct 24 '18 at 17:23
  • Thanks for your recommendation. I am looking at it. I think this might solve my problem. ^_^ – Yunus Oct 24 '18 at 17:30

2 Answers2

1

Set your ListView's divider to null and its Divider Height to 0 pixels:

listView = (ListView) findViewById(R.id.product_list);
listView.setDivider(null);
listView.setDividerHeight(0);
mAdapter = new all_product_list_ArrayAdapter(all_product.this,data);
listView.setAdapter(mAdapter);

more info can be found in the docs for ListView here :

petey
  • 16,914
  • 6
  • 65
  • 97
  • wow that worked like a charm. Can me help me answering the last question ? – Yunus Oct 24 '18 at 18:48
  • @Yunus That would involved changing your listview to a RecyclerView. See this questions answers for that, https://stackoverflow.com/questions/28460300/how-to-build-a-horizontal-listview-with-recyclerview – petey Oct 24 '18 at 19:44
  • Okay . I am looking at RecyclerView. Thanks. – Yunus Oct 25 '18 at 05:44
1

use divider for ListView in this way:

<ListView 
android:id="@+id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:divider="@null"
android:dividerHeight="0dp"/>
nariman amani
  • 263
  • 6
  • 21