我正在处理动态UI。我有一个父LinearLayout,在其中创建了另一个LinearLayout,并在其中添加了TextView。我希望将该TextView右对齐到屏幕。
我尝试了以下方法:
public MessageView(LinearLayout parent, Message msg) {
myParent = parent;
messageDetails = new LinearLayout(parent.getContext());
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT);
layoutParams.gravity = RelativeLayout.ALIGN_PARENT_RIGHT;
messageDetails.setLayoutParams(layoutParams);
senderTV = new TextView(parent.getContext());
senderTV.setTypeface(null, Typeface.ITALIC);
messageDetails.addView(senderTV);
}
我该如何做到这一点?