Изменить высоту просмотра по клику - PullRequest
0 голосов
/ 24 июня 2018

У меня есть TextView, который в настоящее время имеет высоту 0 дп, и я хочу, чтобы он увеличивался на 20 дп с каждым нажатием кнопки

 <TextView
        android:layout_alignParentBottom="true"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="@color/colorPrimary"/>

<Button
    android:layout_centerHorizontal="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

Ответы [ 2 ]

0 голосов
/ 24 июня 2018

Вы можете изменить высоту или размер ваших через sharedpreferences в java, просто объявив sharedpreference в методе onClick вашей кнопки в android, как я это сделал ниже, ваш размер textView будет изменен при нажатии кнопки:

MainActivity_java

Button small = (Button) findViewById(R.id.small);
        small.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                TextView tv = (TextView) findViewById(R.id.teext);
                SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(MainActivity.this.getBaseContext());
                tv.setTextSize(sharedPreferences.getFloat("FONT_SIZE", 30/*DEFAULT VALUE*/));

            }
            });

Main_XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >


    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Say Yes if the size of textView changes" />

    <TextView
        android:id="@+id/teext"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="The Size of text View will change on button click !"/>

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


</LinearLayout>
0 голосов
/ 24 июня 2018

Вы можете программно изменить высоту просмотра текста:

LayoutParams params = (LayoutParams) textView.getLayoutParams();
params.height = 20;
textView.setLayoutParams(params);

Теперь вы можете получить предыдущую высоту и добавлять к ней 20 при каждом нажатии кнопки.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...