2012-07-07 48 views
0

我正在試圖使用SeekBar更改TextView的文本大小,它的工作正常只有當我增加大小,減少時,「文本大小」改變良好,但「textview的佈局」似乎具有最大的放置高度(文本顯示在佈局的中心,就像具有match_parent屬性而不是wrap_content一樣)。如何使用SeekBar的進度調整TextView的大小(Android)

我嘗試的TextView的佈局屬性(它是在RelativeLayout的) 的許多組合(H:WRAP_CONT,W:WRAP_CONT/H:MATCH_PAR,W:MATCH_PAR,阿玲PARENT TOP TRUE/.....)

有人可以幫助我嗎?

編輯:TextView的應出現在頂級

佈局

<LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" > 

     <RelativeLayout 
      android:id="@+id/preview_preview" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" > 

      <ImageView 
       android:id="@+id/preview_image" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" android:background="@drawable/cuadros_001"/> 

      <TextView 
       android:id="@+id/preview_text_top" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:text="TextView" 
       android:textColor="#FFFFFF"/> 

      <TextView 
       android:id="@+id/preview_text_bottom" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginBottom="2.5dp" 
       android:gravity="bottom|center" 
       android:text="PREVIEW_TEXT_BOTTOM" 
       android:textColor="#FFFFFF" 
       android:textSize="25dp" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true"/> 

      </RelativeLayout> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" > 

     <GridView 
      android:id="@+id/preview_gridview" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@drawable/backgroundtransparencia" 
      android:gravity="center" 
      android:horizontalSpacing="5dp" 
      android:numColumns="3" 
      android:stretchMode="columnWidth" 
      android:verticalSpacing="10dp" > 

     </GridView> 

    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/preview_child_2" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" > 

     <Button 
      android:id="@+id/button1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Button" /> 

     <Button 
      android:id="@+id/button2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Button" /> 

    </LinearLayout> 

</ViewFlipper> 

--- SEEKBAR--

seekbar_toptext =(SeekBar)findViewById(R.id.seekbar_toptext); 
    seekbar_toptext.setProgress(40); 
    seekbar_toptext.incrementProgressBy(05); 
    seekbar_toptext.setMax(100); 

    seekbar_toptext.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { 

     int topsize; 

     public void onStopTrackingTouch(SeekBar seekBar) { 
      // TODO Auto-generated method stub 


     } 


     public void onStartTrackingTouch(SeekBar seekBar) { 
      // TODO Auto-generated method stub 
     } 

     public void onProgressChanged(SeekBar seekBar, int progress, 
       boolean fromUser) { 

      preview_text_top.setTextSize(TypedValue.COMPLEX_UNIT_SP ,progress); 

     } 
    }); 

在此先感謝。

+0

嘗試調用['forceLayout()'](http://developer.android.com/參考/ android/view/View.html#forceLayout())在'TextView'及其父。 – 2012-07-07 16:31:03

+0

我嘗試過,但不適合我。 = / – KNU 2012-07-07 16:39:26

回答

0

試試這個代碼...

我希望這將有助於你...

final TextView t1=new TextView(this); 
t1.setText("Hello Android");   
    final SeekBar sk=(SeekBar) findViewById(R.id.seekBar1);  
    sk.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {  

    @Override  
    public void onStopTrackingTouch(SeekBar seekBar) {  
     // TODO Auto-generated method stub  
    }  

    @Override  
    public void onStartTrackingTouch(SeekBar seekBar) {  
     // TODO Auto-generated method stub  
    }  

    @Override  
    public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {  
     // TODO Auto-generated method stub  

     t1.setTextSize(progress); 
     Toast.makeText(getApplicationContext(), String.valueOf(progress),Toast.LENGTH_LONG).show(); 

    }  
});    
相關問題