簡體   English   中英

如何使用SeekBar的進度調整TextView的大小(Android)

[英]How to resize TextView with SeekBar's progress (Android)

我正在嘗試使用SeekBar更改TextView的文本大小,並且只有當我增加大小,減小大小時,“文本大小”才能很好地改變,但是“ textview的布局”似乎具有最大的高度,放置(文本顯示在布局的中心,就好像具有match_parent屬性而不是wrap_content一樣)。

我嘗試了textview的布局屬性的許多組合(位於RelativeLayout中)(H:WRAP_CONT,W:WRAP_CONT / H:MATCH_PAR,W:MATCH_PAR,ALING 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);

        }
    });

提前致謝。

嘗試此代碼...

希望對您有幫助...

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();

    }       
});             

暫無
暫無

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

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