我想創建製作寬屏幕的70%的寬度
[![Design image][1]][1]
[1]: http://i.stack.imgur.com/SCMA5.jpg
我使用的是回收的看法,但我的問題這樣的效果,是每個卡的寬度的100%屏幕爲70%。
下面是每個項目
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_margin="@dimen/scale_20dp"
android:id="@+id/rowLayout"
>
<LinearLayout
android:id="@+id/button_parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/card_view"
>
<LinearLayout
android:id="@+id/currentYear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/paymentscreengrey"
android:orientation="vertical"
android:layout_gravity="center"
android:gravity="center"
android:paddingTop="@dimen/scale_50dp"
android:paddingLeft="35dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="**** **** **** 5432"
android:textSize="@dimen/scale_20dp"
android:textColor="@color/white"
android:layout_marginTop="@dimen/scale_20dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="2345"
android:textSize="@dimen/scale_16dp"
android:textColor="@color/white" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:paddingRight="@dimen/scale_20dp"
android:paddingTop="@dimen/scale_15dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PERSONAL"
android:fontFamily="bold"
android:textColor="@color/white"
android:textSize="18dp"
android:textStyle="bold" />
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="@string/title_valid_up_to"
android:textColor="@color/white"
android:textSize="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="12/15"
android:layout_marginLeft="10dp"
android:textColor="@color/white"
android:textSize="@dimen/text_18"
/>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</LinearLayout>
這裏的XML代碼的視圖中的XML文件保存在回收站視圖真的這樣做的
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/rv"
/>
</LinearLayout>
and finally the recycler view
package com.heyjude.heyjudeapp.adapter;
import android.app.Activity;
import android.graphics.Point;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import com.heyjude.heyjudeapp.R;
import com.heyjude.heyjudeapp.model.Card;
import java.util.ArrayList;
import java.util.List;
public class CheckOutCardRecycler extends RecyclerView.Adapter<CheckOutCardRecycler.CardViewHolder>{
private List<Card> checkOutCard;
private int screenWidth;
public CheckOutCardRecycler(Activity activity, List<Card> checkOutCard){
Display display = activity.getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
this.screenWidth = size.x;
this.checkOutCard = checkOutCard;
}
public static class CardViewHolder extends RecyclerView.ViewHolder {
CardView card;
LinearLayout row;
CardViewHolder(View itemView) {
super(itemView);
row = (LinearLayout)itemView.findViewById(R.id.rowLayout);
card = (CardView)itemView.findViewById(R.id.card_view);
}
}
@Override
public int getItemCount() {
return checkOutCard.size();
}
@Override
public CardViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.row_checkout_cards, viewGroup, false);
CardViewHolder pvh = new CardViewHolder(v);
return pvh;
}
@Override
public void onBindViewHolder(CardViewHolder cardViewHolder, int i) {
}
@Override
public void onAttachedToRecyclerView(Recycler View recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
}
}
而不是回收查看您可以使用具有此功能,您需要通過默認視圖尋呼機[詳見本(http://stackoverflow.com/questions/9907748/viewpager-get-a-partial-view-of-the-the-page) – SaravInfern
你可以動態地將項目添加到viewpager嗎? –
是的,你可以添加/刪除視圖動態查看尋呼機 – SaravInfern