簡體   English   中英

我的TextView文字不可見

[英]My TextView text is not visible

盡管擺弄很多,但我無法使TextView可見。

我已經設置了一個字符串,該字符串應該包含要在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>

`

底部的TextView使中間的圖像居中。 我只是刪除了它並進行了檢查,但是它並沒有解決問題。

不確定,但可能與weightheight屬性中的值有關。 您必須將高度聲明為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" />  

讓我知道這個是否奏效。

我還將在Filo的答案中添加您應該在LinearLayout使用android:weightSum屬性,根據您的布局,該屬性應為100(25 + 50 + 25)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM