[英]TextViews invisible inside LinearLayout?
我在LinearLayout
有一些TextView
。 在運行時, LinearLayout
是可見的,但沒有TextViews
。 這是XML:
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5384615384615385"
android:scaleType="fitXY"
android:adjustViewBounds="true">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
>
<TextView
android:id="@+id/onezero"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="one"
android:typeface="sans"
android:layout_weight="1"
android:layout_margin="17dp"
android:textIsSelectable="true"
android:clickable="true" />
<TextView
android:id="@+id/oneone"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="two"
android:typeface="sans"
android:layout_margin="17dp"
android:textIsSelectable="true"
android:clickable="true" />
<TextView
android:id="@+id/onefour"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="three"
android:layout_weight="1"
android:typeface="sans"
android:layout_margin="17dp"
android:textIsSelectable="true"
android:clickable="true" />
<TextView
android:id="@+id/other"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="four"
android:layout_margin="17dp"
android:typeface="sans"
android:layout_weight="1"
android:textIsSelectable="true"
android:clickable="true" />
</LinearLayout>
<ScrollView
android:id="@+id/scrollview1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
android:fillViewport="true">
<TextView
android:id="@+id/tv1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:typeface="sans"
android:textSize="17sp"
/>
</ScrollView>
</LinearLayout>
</FrameLayout>
如何讓它們可見?
編輯:訪問此布局的代碼:
void fragment(){
ten.setTextColor(0xFFFFFF);//These are the 4 TextViews
eleven.setTextColor(0xFFFFFF);
fourteen.setTextColor(0xFFFFFF);
other.setTextColor(0xFFFFFF);
ten.setVisibility(View.VISIBLE);
eleven.setVisibility(View.VISIBLE);
fourteen.setVisibility(View.VISIBLE);
other.setVisibility(View.VISIBLE);
}
我正在初始化textviews的代碼:
ten=(TextView)findViewById(R.id.onezero);
eleven=(TextView)findViewById(R.id.oneone);
fourteen=(TextView)findViewById(R.id.onefour);
other=(TextView)findViewById(R.id.other);
編輯:我嘗試點擊LinearLayout區域,TextViews正在注冊點擊..這意味着他們在那里,但看不見...
你申請的顏色是白色......
0xFFFFFF
嘗試更改顏色以與布局顏色形成對比。
編輯:
我花了很長時間才意識到這一點..嘗試使用以下代碼:
textview.setTextColor(Color.parseColor("#bdbdbd"));
使用此前綴更改布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
要么
在FrameLayout android:layout_height="0dp"
這將使視圖不可見,可能用於layout_width應該是wrap_content
你正在使用android:layout_weight - 基於比率的空間分布。 為了使它工作,你必須設置:
機器人:layout_width = “0dp”
在xml中添加它
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
然后在java類中更改文本顏色
采用
000000
代替
0xFFFFFF
You have not assigned the layout_height of your parent layout i.e. FrameLayout. Try this:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.5384615384615385"
android:adjustViewBounds="true"
android:scaleType="fitXY" >
<LinearLayout
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:gravity="center"
android:orientation="horizontal" >
<TextView
android:id="@+id/onezero"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="17dp"
android:layout_weight="1"
android:clickable="true"
android:text="one"
android:textIsSelectable="true"
android:typeface="sans" />
<TextView
android:id="@+id/oneone"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="17dp"
android:layout_weight="1"
android:clickable="true"
android:text="two"
android:textIsSelectable="true"
android:typeface="sans" />
<TextView
android:id="@+id/onefour"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="17dp"
android:layout_weight="1"
android:clickable="true"
android:text="three"
android:textIsSelectable="true"
android:typeface="sans" />
<TextView
android:id="@+id/other"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="17dp"
android:layout_weight="1"
android:clickable="true"
android:text="four"
android:textIsSelectable="true"
android:typeface="sans" />
</LinearLayout>
<ScrollView
android:id="@+id/scrollview1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbars="vertical" >
<TextView
android:id="@+id/tv1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="17sp"
android:typeface="sans" />
</ScrollView>
</LinearLayout>
</FrameLayout>
顯然,在以下顏色中使用十六進制代碼:
ten.setTextColor(0xFFFFFF);//These are the 4 TextViews
eleven.setTextColor(0xFFFFFF);
fourteen.setTextColor(0xFFFFFF);
other.setTextColor(0xFFFFFF);
不起作用。 我用Color.WHITE
切換了0xFFFFFF
:
ten.setTextColor(Color.WHITE);//These are the 4 TextViews
eleven.setTextColor(Color.WHITE);
fourteen.setTextColor(Color.WHITE);
other.setTextColor(Color.WHITE);
這非常有效。
編輯:弄清楚為什么十六進制代碼不起作用。 我們需要在每個十六進制的開頭附加一個透明度十六進制。 例如,如果您希望顏色為80%不透明,請按以下步驟查找透明度十六進制:
255 * 0.8 = 204
現在將204轉換為十六進制(使用谷歌),你將得到0xCC
。 在十六進制代碼之前添加它,你將獲得0xCCFFFFFF
。 使用它可以使它完美地工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.