2016-05-10 25 views
0

Wie archiviere ich ein Layout für meinen RecyclerView der wie folgt aussieht: enter image description hereMaterial Design RecyclerView Layout-

Ich habe versucht, es zu schaffen, aber es hat immer in dem giudlines aussehen.

Dies ist aus der Material Design Guidlines, aber ich konnte keine XML-Layouts finden, außer Sketch und PSDs. Gibt es irgendwelche Ressourcen direkt in XML?

Edit 1: Ich brauche nur die einzelne XML-Listenelement Layout

Edit 2: Ich weiß, wie & verwenden, um eine RecyclerView implementieren

+0

Sie müssen 'XML Layout' auf eigene Faust machen. Geh und probier es aus. –

+0

Sie möchten eine Kopfzeilenliste erstellen? –

+0

@Funkyidol die Header-Liste ist nicht wichtig, brauche ich die einzelne Liste Artikellayout –

Antwort

-1

diese offizielle Dokumentation Link finden Sie, wie man Verwenden Sie RecyclerView.LayoutManager http://developer.android.com/training/material/lists-cards.html

+0

Vielen Dank für Ihre Antwort. Ich weiß, wie man einen RecyclerView benutzt, aber ich brauche das xml-Layout, das in den Richtlinien gezeigt wird –

0

Erstellen Sie eine XML, die haben, was Sie wollen Beispiel:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="@drawable/gradient_bg" 
    android:orientation="horizontal" 
    android:layout_margin="1dp" 
    android:padding="1dip" > 

    <LinearLayout android:id="@+id/thumbnail" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:padding="17dip" 
     android:layout_alignParentLeft="true"   
     android:layout_marginRight="2dip"> 
     <ImageView 
      android:id="@+id/gasImagem" 
      android:contentDescription="cover" 
      android:layout_width="100dip" 
      android:layout_height="100dip" 
      /> 
    </LinearLayout> 

    <TextView 
     android:id="@+id/gasTitulo" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignTop="@+id/thumbnail" 
     android:layout_toRightOf="@+id/thumbnail" 
     android:textColor="#040404" 
     android:layout_marginTop="30dp" 
     android:typeface="sans" 
     android:textSize="20sp" 
     android:textStyle="bold"/> 

    <TextView 
     android:id="@+id/gasPreco" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="18sp" 
     android:textColor="#000000" 
     android:textStyle="bold" 
     android:layout_marginTop="95dp" 
     android:layout_toRightOf="@+id/thumbnail"/> 
    <Button 
     android:id="@+id/btCarro" 
     android:layout_width="50dp" 
     android:layout_height="30dp" 
     android:background = "@drawable/roundedbutton" 
     android:layout_marginTop="95dp" 
     android:layout_marginLeft="310dp" 
     android:drawableTop="@drawable/shoppingcart" 
     android:textAlignment="center" 
     /> 
</RelativeLayout> 

After this create an adapter **example** 

    public class MyAdaptadorRecycler extends RecyclerView.Adapter<MyAdaptadorRecycler.ViewHolder> { 

    private List<Produto>gasList; 
    private LayoutInflater layout; 


    public MyAdaptadorRecycler(Context c,List<Produto>l){ 
     gasList = l; 
     layout = (LayoutInflater)c.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    } 

    @Override 
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 
     View v = layout.inflate(R.layout.list_row,parent,false); 
     ViewHolder vh = new ViewHolder(v); 
     return vh; 
    } 



    @Override 
    public void onBindViewHolder(ViewHolder holder, int position) { 
     holder.ivcapa.setImageResource(gasList.get(position).getImagem()); 
     holder.tvtitulo.setText(gasList.get(position).getNome()); 
     holder.tvPreco.setText(String.valueOf(gasList.get(position).getPreco()) + "€"); 
     final int posicao = position; 
     holder.bt.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       Toast.makeText(v.getContext(), "Carrinho: ", Toast.LENGTH_SHORT).show(); 
      } 
     }); 

     holder.itemView.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 
       Toast.makeText(view.getContext(), "Recycle Click", Toast.LENGTH_SHORT).show(); 
      } 
     }); 

    } 

    @Override 
    public int getItemCount() { 
     return gasList.size(); 
    } 


    public static class ViewHolder extends RecyclerView.ViewHolder { 
     protected TextView tvtitulo, tvPreco; 
     protected ImageView ivcapa; 
     protected Button bt; 

     public ViewHolder(View itemView) { 
      super(itemView); 
      this.tvtitulo = (TextView) itemView.findViewById(R.id.gasTitulo); 
      this.ivcapa = (ImageView) itemView.findViewById(R.id.gasImagem); 
      this.tvPreco = (TextView)itemView.findViewById(R.id.gasPreco); 
      this.bt = (Button)itemView.findViewById(R.id.btCarro); 
     } 


    } 


} 

Vielleicht benötigen Sie einen Teiler exemple:

public class DividerItemDecoration extends RecyclerView.ItemDecoration { 
    private final int mVerticalSpaceHeight; 

    public DividerItemDecoration(int mVerticalSpaceHeight) { 
     this.mVerticalSpaceHeight = mVerticalSpaceHeight; 
    } 

    @Override 
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, 
           RecyclerView.State state) { 
     outRect.bottom = mVerticalSpaceHeight; 
     //outRect.left = mVerticalSpaceHeight; 
     //outRect.right = mVerticalSpaceHeight; 
    } 
} 


then in your mainActivity you **need to do this:** 



     LinearLayoutManager llm = new LinearLayoutManager(this); 
     this.rv.setLayoutManager(llm); 
     rv.addItemDecoration(new DividerItemDecoration(20)); 
     rv.setHasFixedSize(true); 
     nr= 1; 
     this.listaPordutos = new ArrayList<Produto>(); 
     this.adapatadorLivros = new MyAdaptadorRecycler(this, listaPordutos); 
     rv.setAdapter(this.adapatadorLivros); 

Das ist mein exemples nur, dass ich das ein Programm

Hoffnung erstellen können Ihnen helfen, jeder Zweifel einfach sagen :)