下面列出了android.widget.LinearLayout#getParent ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
static void createListenerLog(LinearLayout messagesContainer, String text) {
String currentDateTime = new SimpleDateFormat("HH:mm:ss.SSS", Locale.getDefault()).format(new Date());
TextView textView = new TextView(messagesContainer.getContext());
textView.setTextColor(Color.WHITE);
textView.setTextSize(14);
textView.setText(currentDateTime + ": " + text);
messagesContainer.addView(textView);
final ScrollView scrollView = (ScrollView)messagesContainer.getParent();
scrollView.post(new Runnable() {
public void run() {
scrollView.fullScroll(ScrollView.FOCUS_DOWN);
}
});
}
/**
* Procedure returns the layout depth of this term related to mainView
*/
public static int getLayoutDepth(LinearLayout l)
{
int retValue = 0;
if (l == null)
{
return retValue;
}
ViewParent p = l.getParent();
while (p != null)
{
if (p instanceof TwoDScrollView)
{
if (((TwoDScrollView) p).getId() == R.id.main_scroll_view)
{
break;
}
}
if (p instanceof FormulaBase && p.getParent() == null)
{
retValue += 2;
break;
}
retValue++;
p = p.getParent();
}
return retValue;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.act_list_btn);
TAG = this.getClass().getSimpleName();
Log.setTag(TAG);
container = (LinearLayout) findViewById(R.id.container);
scroll = (ScrollView) container.getParent();
TextView tv = (TextView) container.findViewById(R.id.title);
tv.setText(getMainTitle());
mTvSubTitle = (TextView) container.findViewById(R.id.sub_title);
String[] bttxt = getButtonTexts();
if (bttxt != null) {
for (int i = 0; i < bttxt.length; i++) {
Button bt = new Button(this);
LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
int margin = getResources().getDimensionPixelSize(R.dimen.common_marin);
lp.setMargins(margin, margin, margin, margin);
bt.setId(i);
bt.setText(bttxt[i]);
bt.setOnClickListener(this);
bt.setLayoutParams(lp);
container.addView(bt);
}
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.act_list_btn);
TAG = this.getClass().getSimpleName();
OrmLog.setTag(TAG);
container = (LinearLayout) findViewById(R.id.container);
scroll = (ScrollView) container.getParent();
TextView tv = (TextView) container.findViewById(R.id.title);
tv.setText(getMainTitle());
mTvSubTitle = (TextView) container.findViewById(R.id.sub_title);
String[] bttxt = getButtonTexts();
if (bttxt != null) {
for (int i = 0; i < bttxt.length; i++) {
Button bt = new Button(this);
LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
int margin = getResources().getDimensionPixelSize(R.dimen.common_marin);
lp.setMargins(margin, margin, margin, margin);
bt.setId(i);
bt.setText(bttxt[i]);
bt.setOnClickListener(this);
bt.setLayoutParams(lp);
container.addView(bt);
}
}
}
@CallSuper
protected void updateLayoutForReceive(VH holder) {
ViewGroup frameLayout = (ViewGroup) holder.itemView.findViewById(R.id.mainContainer);
ImageView imgTick = (ImageView) holder.itemView.findViewById(R.id.cslr_txt_tic);
TextView messageText = (TextView) holder.itemView.findViewById(R.id.messageSenderTextMessage);
LinearLayout root = (LinearLayout) holder.itemView.findViewById(R.id.contentContainer);
LinearLayout timeLayout = (LinearLayout) root.getParent();
timeLayout.setGravity(Gravity.LEFT);
if (messageText != null) {
messageText.setTextColor(Color.parseColor(G.textBubble));
}
// ProtoGlobal.RoomMessageType messageType = mMessage.forwardedFrom == null ? mMessage.messageType : mMessage.forwardedFrom.getMessageType();
if (G.isDarkTheme) {
setTextColor(imgTick, R.color.white);
} else {
setTextColor(imgTick, R.color.colorOldBlack);
}
((FrameLayout.LayoutParams) frameLayout.getLayoutParams()).gravity = Gravity.LEFT;
((LinearLayout.LayoutParams) root.getLayoutParams()).gravity = Gravity.LEFT;
if (G.isDarkTheme) {
((View) (holder.itemView.findViewById(R.id.contentContainer)).getParent()).setBackgroundResource(R.drawable.rectangel_white_round_dark);
} else {
((View) (holder.itemView.findViewById(R.id.contentContainer)).getParent()).setBackgroundResource(R.drawable.rectangel_white_round);
}
/**
* add main layout margin to prevent getting match parent completely
* set to mainContainer not itemView because of selecting item foreground
*/
GradientDrawable circleDarkColor = (GradientDrawable) ((View) root.getParent()).getBackground();
circleDarkColor.setColor(Color.parseColor(G.bubbleChatReceive));
((FrameLayout.LayoutParams) frameLayout.getLayoutParams()).leftMargin = (int) holder.itemView.getContext().getResources().getDimension(R.dimen.dp10);
((FrameLayout.LayoutParams) frameLayout.getLayoutParams()).rightMargin = (int) holder.itemView.getContext().getResources().getDimension(R.dimen.dp28);
}
@CallSuper
protected void updateLayoutForSend(VH holder) {
ViewGroup frameLayout = (ViewGroup) holder.itemView.findViewById(R.id.mainContainer);
((FrameLayout.LayoutParams) frameLayout.getLayoutParams()).gravity = Gravity.RIGHT;
LinearLayout root = (LinearLayout) holder.itemView.findViewById(R.id.contentContainer);
((LinearLayout.LayoutParams) root.getLayoutParams()).gravity = Gravity.RIGHT;
LinearLayout timeLayout = (LinearLayout) root.getParent();
timeLayout.setGravity(Gravity.RIGHT);
ImageView imgTick = (ImageView) holder.itemView.findViewById(R.id.cslr_txt_tic);
TextView messageText = (TextView) holder.itemView.findViewById(R.id.messageSenderTextMessage);
// TextView iconHearing = (TextView) holder.itemView.findViewById(R.id.cslr_txt_hearing);
if (messageText != null) {
messageText.setTextColor(Color.parseColor(G.textBubble));
}
// ProtoGlobal.RoomMessageType messageType = mMessage.forwardedFrom == null ? mMessage.messageType : mMessage.forwardedFrom.getMessageType();
ProtoGlobal.RoomMessageStatus status = ProtoGlobal.RoomMessageStatus.UNRECOGNIZED;
if (mMessage.status != null) {
try {
status = ProtoGlobal.RoomMessageStatus.valueOf(mMessage.status);
} catch (RuntimeException e) {
e.printStackTrace();
}
}
if (status == ProtoGlobal.RoomMessageStatus.SEEN) {
if (G.isDarkTheme) {
setTextColor(imgTick, R.color.iGapColor);
} else {
setTextColor(imgTick, R.color.backgroundColorCall2);
}
} else if (status == ProtoGlobal.RoomMessageStatus.LISTENED) {
// iconHearing.setVisibility(View.VISIBLE);
if (G.isDarkTheme) {
setTextColor(imgTick, R.color.iGapColor);
} else {
setTextColor(imgTick, R.color.backgroundColorCall2);
}
imgTick.setVisibility(View.VISIBLE);
} else {
// setTextColor(imgTick, Color.parseColor(G.txtIconCheck));
imgTick.setColorFilter(Color.parseColor(G.txtIconCheck));
}
if (G.isDarkTheme) {
((View) (holder.itemView.findViewById(R.id.contentContainer)).getParent()).setBackgroundResource(R.drawable.rectangle_send_round_color_dark);
} else {
((View) (holder.itemView.findViewById(R.id.contentContainer)).getParent()).setBackgroundResource(R.drawable.rectangle_send_round_color);
}
GradientDrawable circleDarkColor = (GradientDrawable) ((View) root.getParent()).getBackground();
circleDarkColor.setColor(Color.parseColor(G.bubbleChatSend));
/**
* add main layout margin to prevent getting match parent completely
* set to mainContainer not itemView because of selecting item foreground
*/
((FrameLayout.LayoutParams) frameLayout.getLayoutParams()).leftMargin = (int) holder.itemView.getContext().getResources().getDimension(R.dimen.dp28);
((FrameLayout.LayoutParams) frameLayout.getLayoutParams()).rightMargin = (int) holder.itemView.getContext().getResources().getDimension(R.dimen.dp10);
//((LinearLayout.LayoutParams) (holder.itemView.findViewById(R.id.contentContainer).getLayoutParams())).rightMargin = (int) holder.itemView.getResources().getDimension(R.dimen.messageBox_minusLeftRightMargin);
//((LinearLayout.LayoutParams) (holder.itemView.findViewById(R.id.contentContainer).getLayoutParams())).leftMargin = 0;
}
@Test
public void testDrawSysTrayParentLayoutVisibility() {
LinearLayout sysTrayLayout = initializeSysTrayLayout(POSITION_BOTTOM_RIGHT);
ViewGroup parent = (ViewGroup) sysTrayLayout.getParent();
assertEquals(View.VISIBLE, parent.getVisibility());
}