2016-08-04 37 views
0

我有切換按鈕內線性佈局和點擊他們不顯示ontext和offtext.I也有所有切換按鈕和內部onclick函數的監聽器我試圖設置ontext但它不起作用。切換按鈕內線性佈局不顯示關文字

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
android:orientation="vertical"> 

<fragment 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:name="com.example.sharmila.eeeeeee.tryfragment" 
    android:id="@+id/fragment" 
    android:layout_centerHorizontal="true" 
    tools:layout="@layout/try_fragment" /> 

    <LinearLayout android:id="@+id/linearlayout" 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="50dp" 
    android:layout_below="@+id/fragment" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="20dp" 
    android:weightSum="1"> 

    <ToggleButton 
     android:layout_width="49dp" 
     android:layout_height="40dp" 
     android:id="@+id/wholenote" 
     android:layout_row="0" 
     android:layout_column="0" 
     android:background="@drawable/a" 
     android:textOff="" 
     android:textOn="S" 
     android:textSize="700dp" 
     android:textColor="#ff0000" 
     /> 

    <ToggleButton 
     android:layout_width="49dp" 
     android:layout_height="40dp" 
     android:id="@+id/halfnote" 
     android:layout_row="0" 
     android:layout_column="1" 
     android:background="@drawable/b" 
     android:textOff="" 
     android:textOn="S" 
     android:textSize="700dp" 
     android:textColor="#ff0000"/> 

    <ToggleButton 
     android:layout_width="49dp" 
     android:layout_height="40dp" 
     android:id="@+id/quarternote" 
     android:layout_row="0" 
     android:layout_column="2" 
     android:background="@drawable/c" 
     android:textOff="" 
     android:textOn="S" 
     android:textSize="700dp" 
     android:textColor="#ff0000" 
     /> 

    <ToggleButton 
     android:layout_width="49dp" 
     android:layout_height="40dp" 
     android:id="@+id/eightnote" 
     android:layout_row="0" 
     android:layout_column="3" 
     android:background="@drawable/d" 
     android:textOn="S" 
     android:textSize="700dp" 
     android:textColor="#ff0000" 
     android:textOff=""/> 

    <ToggleButton 
     android:layout_width="49dp" 
     android:layout_height="40dp" 
     android:id="@+id/sixteennote" 
     android:textOn="S" 
     android:textSize="700dp" 
     android:textColor="#ff0000" 
     android:textOff="" 
     android:layout_row="0" 
     android:layout_column="4" 
     android:background="@drawable/e" 
     /> 

    <ToggleButton 
     android:layout_width="49dp" 
     android:layout_height="40dp" 
     android:textOn="S" 
     android:textSize="700dp" 
     android:textColor="#ff0000" 
     android:id="@+id/thirtytwonote" 
     android:layout_row="0" 
     android:layout_column="5" 
     android:background="@drawable/g" 
     /> 

    <ToggleButton 
     android:layout_width="49dp" 
     android:layout_height="40dp" 
     android:textOn="S" 
     android:textSize="700dp" 
     android:textColor="#ff0000" 
     android:id="@+id/sixyfournote" 
     android:layout_row="0" 
     android:layout_column="6" 
     android:background="@drawable/f" 
     /> 
    </LinearLayout> 
    <TableRow android:id="@+id/Linearlayout2" 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="50dp" 
    android:layout_below="@+id/linearlayout" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="20dp" 
    android:weightSum="1"> 
    <View 
     android:layout_width="10dp" 
     android:layout_height="40dp" 
     android:layout_weight="0.34" /> 
     <ImageButton 
     android:layout_width="49dp" 
     android:layout_height="40dp" 
     android:id="@+id/pause" 
     android:layout_row="0" 
     android:layout_column="1" 
     android:src="@drawable/pause" /> 
    <View 
     android:layout_width="10dp" 
     android:layout_height="40dp" 
     android:layout_weight="0.18" /> 

    <ImageButton 
     android:layout_width="49dp" 
     android:layout_height="40dp" 
     android:id="@+id/play" 
     android:layout_row="0" 
     android:layout_column="3" 
     android:src="@drawable/play" /> 
    <View 
     android:layout_width="10dp" 
     android:layout_height="40dp" 
     android:layout_weight="0.18" /> 

    <ImageButton 
     android:layout_width="49dp" 
     android:layout_height="40dp" 
     android:id="@+id/stop" 
     android:src="@drawable/stop" 
     android:layout_row="0" 
     android:layout_column="3"/> 

</TableRow> 


<GridLayout 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/gridView" 
    android:layout_below="@+id/Linearlayout2" 
    > 

    <Button 
     android:layout_width="78dp" 
     android:layout_height="wrap_content" 
     android:text="Prev" 
     android:id="@+id/previous" 
     android:layout_row="0" 
     android:layout_column="2" /> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Next" 
     android:id="@+id/next" 
     android:layout_row="0" 
     android:layout_column="19" /> 
    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="save" 
     android:id="@+id/save" 
     android:layout_row="1" 
     android:layout_column="1" /> 


    <Button 
     android:layout_width="99dp" 
     android:layout_height="wrap_content" 
     android:text="Finish" 
     android:id="@+id/finish" 
     android:layout_row="1" 
     android:layout_column="21" /> 

</GridLayout> 

活動代碼:

private static ToggleButton wholenote; 
private static ToggleButton halfnote; 
private static ToggleButton quarternote; 
private static ToggleButton eighthnote; 
private static ToggleButton sixteenthnote; 
private static ToggleButton thirtytwonote; 
private static ToggleButton sixtyfourthnote; 
private static String selected = "01"; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    wholenote = (ToggleButton) findViewById(R.id.wholenote); 
    wholenote.setOnClickListener(this); 
    halfnote = (ToggleButton) findViewById(R.id.halfnote); 
    halfnote.setOnClickListener(this); 
    quarternote = (ToggleButton) findViewById(R.id.quarternote); 
    quarternote.setOnClickListener(this); 
    eighthnote = (ToggleButton) findViewById(R.id.eightnote); 
    eighthnote.setOnClickListener(this); 
    sixteenthnote = (ToggleButton) findViewById(R.id.sixteennote); 
    sixteenthnote.setOnClickListener(this); 
    thirtytwonote = (ToggleButton) findViewById(R.id.thirtytwonote); 
    thirtytwonote.setOnClickListener(this); 
    sixtyfourthnote = (ToggleButton) findViewById(R.id.sixyfournote); 
    sixtyfourthnote.setOnClickListener(this); 

    } 
public void onClick(View view) { 
     switch (view.getId()) { 
    case R.id.wholenote: 
      wholenote.setTextOn("S"); 
      break; 
     case R.id.halfnote: 
      halfnote.setTextOn("S"); 
      break; 
     case R.id.quarternote: 
      quarternote.setTextOn("S"); 
      break; 
     case R.id.eightnote: 
      eightnote.setTextOn("S"); 
      break; 
     case R.id.sixteennote: 
      sixteennote.setTextOn("S"); 
      break; 
     case R.id.thirtytwonote: 
      thirtytwonote.setTextOn("S"); 
      break; 
     case R.id.sixyfournote: 
      sixtyfournote.setTextOn("S"); 
      break; 
     } 
    } 
+0

活動代碼? –

回答

0
android:textSize="700dp" 

它沒有出現在關的文字,那是因爲你的文字尺寸過大,以顯示它在屏幕上。 設置所有togglebuttons textSize 10dp。

android:textSize="10dp" 
+0

我這樣做了一個愚蠢的錯誤。感謝您指出:)它的工作 – Sarmila

+1

那麼如何表示讚賞Sarmila,並將答案標記爲接受? – lionscribe

+0

@lionscribe我該怎麼辦? – turbofan