【发布时间】:2021-08-05 18:24:28
【问题描述】:
我正在制作聊天应用程序,并希望在消息应用程序中设置消息样式。
这是我为它们设置样式的代码:
textView.setTextColor(Color.parseColor("#FFFFFFFF"));
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
params.setMargins(400,0,10,10);
params.gravity = Gravity.END;
textView.setLayoutParams(params);
linearLayout.addView(textView);
这是我的 XML 代码:
<ScrollView
android:id="@+id/scroll"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="bottom"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="12dp"
android:background="@drawable/background"
android:layout_marginBottom="16dp"
app:layout_constraintBottom_toTopOf="@+id/editTextTextPersonName2"
app:layout_constraintTop_toBottomOf="@+id/name">
<LinearLayout
android:id="@+id/chatMessages"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</LinearLayout>
</ScrollView>
我的 TextView 被添加到这个 ^ 线性布局中。
这就是我在应用程序中收到的内容:(不要翻译消息,它们仅用于测试目的,它们很愚蠢)
我不知道为什么会出现这些差距,请有人帮助我。
【问题讨论】:
标签: java android android-xml