2014-04-19 38 views
1

儘管有太多的擺弄,我無法使我的TextView可見。我的TextView文本不可見

我已經設置了一個字符串,該字符串應該包含要在TextView中顯示的文本,但文本在圖形佈局中永遠不會顯示。即使我用 「機器人:文本=」 文本」,並更改尺寸,外觀等,沒有什麼變化

我的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是被那裏,在中間圖像居中,而我剛剛刪除它,並選中,但它沒有解決問題。

+1

你可以改變LinearLayout的背景圖像而不是檢查。 –

+0

我沒有看到您的代碼和佈局的任何問題。檢查你的代碼的其他部分。 – Libin

回答

0

不確定,但可能與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" /> 

讓我知道這是否正常工作。

+0

啊,現在已經排序!我的小弟前來幫忙,並指出我需要在我的TextView中插入: android:text =「@ string/app_name」 。然而,感謝您的及時回覆! – BipBapApps

0

我還會在Filo的答案中增加android:weightSum屬性LinearLayout,根據你的佈局應該是100(25 + 50 + 25)。

+0

完成:)我在編碼方面頗爲新穎;我唯一真正的以前的經驗是在Scratch和HTML中涉獵,所以我很感激幫助! – BipBapApps