所以,我試圖讓一個TextView
填補一個ImageView
留下的空間時,它是GONE
......我用LinearLayout
和RelativeLayout
試過,但的ImageView空間ISN」 t由TextView拍攝。查看填充空間,如果兄弟走了
那麼,我如何讓它工作?
代碼:
<RelativeLayout
android:orientation="horizontal"
android:id="@+id/cabecalho"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:id="@+id/imgPrimary"
android:visibility="gone"
android:src="@drawable/abc_btn_rating_star_on_mtrl_alpha"
android:tint="#ecac31"
android:layout_gravity="center_vertical"
android:padding="3dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="17dp"
android:text="Endereço de Teste"
android:layout_toRightOf="@+id/imgPrimary"
android:layout_toLeftOf="@+id/btnEdit"
android:layout_centerVertical="true"
android:id="@+id/addrTitle"
android:layout_weight="50"
android:textColor="@color/black"
android:layout_gravity="center_vertical"
android:layout_marginLeft="5dp" />
<ImageButton
android:layout_width="40dp"
android:layout_height="40dp"
android:id="@+id/btnEdit"
android:layout_weight="1"
android:layout_toLeftOf="@+id/btnDelete"
android:src="@drawable/icon_write_location"
android:tint="#08b8ae"
android:scaleType="fitCenter"
android:background="@color/white"
android:padding="10dp" />
<ImageButton
android:layout_width="40dp"
android:layout_height="40dp"
android:id="@+id/btnDelete"
android:layout_weight="1"
android:scaleType="fitXY"
android:src="@drawable/abc_ic_clear_mtrl_alpha"
android:tint="#d60d0d"
android:layout_alignParentRight="true"
android:background="@color/white"
android:padding="7dp" />
</RelativeLayout>
請求的打印: 空間是大膽「阿泰斯特」的在白牌的頂部右側。從我recyclerview適配器
代碼:
public class AddrAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private List<Address> addressList;
public class ViewHolder extends RecyclerView.ViewHolder {
public LinearLayout layout;
public TextView titulo, enderecoCompleto;
public ImageButton btnEdit, btnDelete;
public ImageView isDefaultStar;
//public RelativeLayout cabecalho;
public ViewHolder(LinearLayout layout) {
super(layout);
this.layout = layout;
this.titulo = (TextView) layout.findViewById(R.id.addrTitle);
this.enderecoCompleto = (TextView) layout.findViewById(R.id.addrComplete);
this.btnEdit = (ImageButton) layout.findViewById(R.id.btnEdit);
this.btnDelete = (ImageButton) layout.findViewById(R.id.btnDelete);
this.isDefaultStar = (ImageView) layout.findViewById(R.id.imgPrimary);
//this.cabecalho = (RelativeLayout) layout.findViewById(R.id.cabecalho);
}
}
public class ViewHolderHint extends RecyclerView.ViewHolder {
public TextView text;
public ViewHolderHint(TextView text) {
super(text);
this.text = text;
}
}
public AddrAdapter(List<Address> addresses) {
this.addressList = addresses;
if (addresses.size() > 0 && this.addressList.get(0).getCity() != null) {
this.addressList.add(0, new Address());
}
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
switch (viewType) {
case 0 : {
TextView v = (TextView) LayoutInflater.from(parent.getContext())
.inflate(R.layout.card_address_hint, parent, false);
ViewHolderHint vhh = new ViewHolderHint(v);
return vhh;
}
default : {
LinearLayout v = (LinearLayout) LayoutInflater.from(parent.getContext())
.inflate(R.layout.card_address, parent, false);
ViewHolder vh = new ViewHolder(v);
return vh;
}
}
}
@SuppressLint("SetTextI18n")
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
if (position < 1) {
ViewHolderHint hint = (ViewHolderHint) holder;
hint.text.setText(Html.fromHtml("Selecione um <b>endereço de entrega</b>"));
} else {
final ViewHolder layout = (ViewHolder) holder;
layout.isDefaultStar.setVisibility((addressList.get(position).getDefaultAddress()) ? View.VISIBLE : View.GONE);
//layout.cabecalho.requestLayout();
layout.titulo.setText(addressList.get(position).getTitle());
layout.enderecoCompleto.setText(
addressList.get(position).getDescription()+", "+
addressList.get(position).getNumber()+"\n"+
addressList.get(position).getComplement()+", "+
addressList.get(position).getNeighborhood()+" - "+
addressList.get(position).getCity().getName()+" - "+
addressList.get(position).getCity().getState().getCode()+"\n"+
addressList.get(position).getZipcode()
);
layout.btnEdit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int pos = layout.getAdapterPosition();
Address addr = addressList.get(pos);
Bundle b = new Bundle();
b.putSerializable("ADDRESS_TO_EDIT",addr);
b.putInt("CHAVE_ENDERECO",pos); // TODO: Talvez no futuro seja a ID do endereço
Intent i = new Intent(AddressActivity.this,CheckoutAddressAddEditActivity.class);
i.putExtras(b);
startActivityForResult(i,006);
}
});
layout.btnDelete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int pos = layout.getAdapterPosition();
addresses.remove(pos);
notifyItemRemoved(pos);
}
});
layout.layout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int pos = layout.getAdapterPosition();
Address addr = addressList.get(pos);
Bundle extras = new Bundle();
extras.putSerializable("ADDRESS", addr);
Intent data = new Intent();
data.putExtras(extras);
setResult(RESULT_OK, data);
finish();
}
});
}
}
@Override
public int getItemCount() {
return addresses.size();
}
@Override
public int getItemViewType(int pos) {
return (pos > 0) ? 1 : 0;
}
}
你可以分享你的屏幕,如果沒有太大的麻煩? – Shaishav
關於你在說哪個imageView?首先,'imgPrimary'? –
@SergeyGlotov是... –