不能够调整在Android上的同一行两个文本的意见不能够、文本、两个、意见

2023-09-12 05:52:21 作者:霜迟.

XML文件,

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical"  
  android:id="@+id/profileLayout">

  <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Super Powers"  
    />
</LinearLayout>

在活动的文件,我想添加一个文本费尔德,其价值会动态变化(值将是ON或OFF),而该文本应该是内嵌超级大国

and in Activity file i am trying to add one text feild whose value will change dynamically (value will be either ON or OFF) and that text should be inline with "Super Powers"

TextView valueTV = new TextView(this);
valueTV.setText("OFF");
valueTV.setId(5);
valueTV.setGravity(Gravity.RIGHT);
valueTV.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));

((LinearLayout) linearLayout).addView(valueTV);

有谁能够告诉我如何做两个textViews内联?

can anybody tell me how to make two textViews inline?

推荐答案

您的LinearLayout具有垂直方向。它应是水平的,以便能够将其子在同一行中。

Your LinearLayout has vertical orientation. It should be horizontal to be able to place its children in the same line.