1)我動態地創建了一些控件。我有一箇中等大小的帶有EditText的RelativeLayout,可以填充大部分父視覺空間。其餘部分由另一個視圖覆蓋,佈局應該在點擊時滑動。問題是當用戶點擊EditText時,佈局未收到onClick事件。我無法使用TextView,因爲我需要用戶稍後輸入一些文本。我試過這個代碼,沒有成功Android EditText阻止其父母的OnClickListener
private void addTopView() {
RelativeLayout midView = new RelativeLayout(this);
ImageView imageView = new ImageView(this);
imageView.setImageResource(R.drawable.wallet_top);
imageView.setBackgroundColor(0xffff0000);
RelativeLayout.LayoutParams lp = new LayoutParams(scale(320), scale(heightTop));
midView.addView(imageView, lp);
RelativeLayout topCard = populateTPasses ? addTpass(0) : addCard(0);
topCard.setOnClickListener(topCardClick);
midView.addView(topCard);
lp = new LayoutParams(scale(320), scale(cardTopOffsetY + cardHeight));
lp.topMargin = scale(upperOffset);
walletScrollView.addView(midView, lp);
}
private RelativeLayout addCard(int indexVal) {
String cardName = "Add Credit Card";
String cardNum = "Max 16 digits";
String cardCVC = "Max 6 digits";
boolean switchStatus = NO;
String cardExpiry = dateFormatter.format(new Date());
if(indexVal < creditcards.size())
{
cardName = creditcards.get(indexVal).name;
cardNum = String.format("........%s", creditcards.get(indexVal).display);
cardCVC = "NOT STORED";
cardExpiry = creditcards.get(indexVal).expiry;
switchStatus = creditcards.get(indexVal).isDefault;
}
LayoutParams lp = new LayoutParams(scale(cardWidth), scale(cardHeight));
lp.leftMargin = scale(cardTopOffsetX);
lp.topMargin = scale(cardTopOffsetY);
RelativeLayout layout = new RelativeLayout(this);
layout.setLayoutParams(lp);
layout.setTag(indexVal);
addCardElements(layout, cardName, cardNum, cardExpiry, cardCVC, switchStatus);
return layout;
}
private ImageView addCardElements(RelativeLayout whichCard, String cardName, String cardNumber, String cardExpiry, String cardCVC, boolean defaultStatus) {
whichCard.setBackgroundResource(R.drawable.credit_card_tpay);
//Add card name
EditText cardNameField = addCardName(cardName);
whichCard.addView(cardNameField);
return null;
}
private EditText addCardName(String cName) {
EditText cardName = new EditText(this);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(scale(cardWidth - 90), LayoutParams.WRAP_CONTENT);
params.leftMargin = scale(32 + 50);
params.topMargin = scale(15);
cardName.setBackgroundColor(Color.TRANSPARENT);
cardName.setLayoutParams(params);
cardName.setTextColor(Color.WHITE);
if(isLast == NO || (_selectedIndex >= creditcards.size() && creditcards.size() != 0))
cardName.setText(cName);
else
{
cardName.setHint(cName);
}
isLast = NO;
cardName.setTag(kTag_CardName);
if(_selectedIndex >= creditcards.size())
cardName.setEnabled(YES);
else {
cardName.setEnabled(NO);
cardName.setFocusable(NO);
cardName.setFocusableInTouchMode(NO);
cardName.setClickable(NO);
cardName.setBackgroundColor(Color.YELLOW);
}
cardName.setGravity(5);
return cardName;
}
2)這個問題解決了。當我的佈局在TranslateAnimation的幫助下向上滑動時,我必須將其從其父視圖中移除並放到另一個ViewGroup上,否則所有用戶輸入都會中斷。然後它隨着父母的類似變化而回退。在這個過程中,我將佈局的OnClickListener設置爲null並返回給我的偵聽器。問題是,在此之後,偵聽器不會觸發,佈局只能滑動一次。我想知道可能會導致這種情況。
更多與聽者的代碼可能會有所幫助。 –
問題2通過在更改佈局父項之前移動調用來取消動畫*來解決。然而,EditText仍然阻止它的父級OnClickListener ... –