gpt4 book ai didi

java - 如何在 LinearLayout 中显示在其他布局上播放的 TextView?

转载 作者:行者123 更新时间:2023-12-01 05:51:24 25 4
gpt4 key购买 nike

美好的一天。

我有三个布局:第一个是根,第二个和第三个位于第一个。我尝试在第三个布局中添加 TextView 对象,并且对象已添加到第三个布局中(我在 debage 模式下看到它),但该对象没有显示在屏幕上。

有人知道问题出在哪里吗?

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">

<LinearLayout

android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<Button
android:id="@+id/addJokeButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name"
/>

<EditText
android:id="@+id/newJokeEditText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>

</LinearLayout>

<LinearLayout

android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">

</LinearLayout>

</LinearLayout>

protected void initLayout() {
setContentView(R.layout.advanced);

LinearLayout linearLayout = (LinearLayout) getLayoutInflater().inflate(
R.layout.advanced, null);
m_vwJokeEditText = (EditText) findViewById(R.id.newJokeEditText);
m_vwJokeButton = (Button) findViewById(R.id.addJokeButton);
m_vwJokeLayout = (LinearLayout) linearLayout.getChildAt(1);
}

protected void addJoke(Joke joke) {
m_arrJokeList.add(joke);

LayoutParams lparams = new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
TextView textView = new TextView(this);
setColor(textView);
textView.setLayoutParams(lparams);
textView.setText(joke.getJoke());

m_vwJokeLayout.addView(textView);
}

最佳答案

引用此示例

  package com.example.helloandroid;

import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.LinearLayout.LayoutParams;

public class HelloAndroid extends Activity {
TextView textview;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LinearLayout ll= (LinearLayout) findViewById(R.id.LinearLayout01);


LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams
(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

LinearLayout childLayout= new LinearLayout(this);
childLayout.setOrientation(LinearLayout.VERTICAL);
TextView text = new TextView(this);
text.setText("High");
childLayout.addView(text);
ll.addView(childLayout, lp);

}

}`

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
android:id="@+id/LinearLayout01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:id="@+id/textview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="@string/hello"/>
</LinearLayout>

或使用以下链接

Creating Linear Layout with TextViews using a for loop

关于java - 如何在 LinearLayout 中显示在其他布局上播放的 TextView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4573781/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com