Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/184.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我的文本视图文本不可见_Java_Android_Textview - Fatal编程技术网

Java 我的文本视图文本不可见

Java 我的文本视图文本不可见,java,android,textview,Java,Android,Textview,尽管做了很多修改,我还是无法让我的文本视图可见 我设置了一个字符串,该字符串应该包含要在TextView中显示的文本,但在图形布局中从未看到该文本。即使我使用“android:text=“text”,并更改大小、外观等,也不会有任何变化 我的Java代码: public class MainClass extends Activity { float goldCount = 0.0f; ImageView minionClick; TextView textGoldCount;

尽管做了很多修改,我还是无法让我的文本视图可见

我设置了一个字符串,该字符串应该包含要在TextView中显示的文本,但在图形布局中从未看到该文本。即使我使用“android:text=“text”,并更改大小、外观等,也不会有任何变化

我的Java代码:

    public class MainClass extends Activity {

    float goldCount = 0.0f;
ImageView minionClick;
TextView textGoldCount;
String textTotal;

@Override
public void onCreate (Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mainlayout);

    minionClick = (ImageView) findViewById(R.id.minioncentreid);
    textGoldCount = (TextView) findViewById(R.id.textviewtop);

    textTotal = goldCount + " Gold";


    textGoldCount.setText(textTotal);`

我的XML代码:

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

<TextView
    android:id="@+id/textviewtop"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="25">

</TextView>
<ImageView
    android:id="@+id/minioncentreid"
    android:layout_width="fill_parent"
    android:layout_height="0dip"
    android:layout_weight="50"
    android:contentDescription="@+string/desc"
    android:src="@drawable/minioncentrethree"
    />
<TextView 
    android:id="@+id/textviewbottom"
    android:layout_weight="25"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    >
    </TextView>
`
`


底部的文本视图是以中间的图像为中心的,我刚刚删除并检查,但是它没有解决问题。

不确定,但是它可能与<代码>权重和<代码>高度> /代码>属性有关。必须将高度声明为<代码> 0 /代码>如下:

<TextView
    android:id="@+id/textviewtop"
    android:layout_width="fill_parent"
    android:layout_height="0dip"
    android:layout_weight="1" >  // 25 and 50 can be replaced by 1 and 2

<ImageView
    android:id="@+id/minioncentreid"
    android:layout_width="fill_parent"
    android:layout_height="0dip"
    android:layout_weight="2"
    android:contentDescription="@+string/desc"
    android:src="@drawable/minioncentrethree" />

<TextView 
    android:id="@+id/textviewbottom"
    android:layout_weight="1"
    android:layout_height="0dip"
    android:layout_width="wrap_content" />  
//25和50可以用1和2代替

让我知道这是否有效。

我还将在Filo的回答中添加一点,即您应该在
线性布局中使用
android:weightSum
属性,该属性应为100(25+50+25)根据您的布局。

您可以更改LinearLayout的背景图像,然后检查。我看不出您的代码和布局有任何问题。检查代码的其他部分。啊,现在已经排序了!我的小弟弟来帮忙,并指出我需要插入行:android:text=“@string/app\u name“进入我的文本视图。不过,感谢您的及时回复!完成:)我对编码相当陌生;我以前唯一真正的经验是抓挠和涉猎HTML,所以我感谢您的帮助!