helloWorld
helloWorld

Reputation: 219

Cant change size of TextView

Font size is changed but the other view doesn't move. I cant add In this layout any elements. I can only modify existing view, for example i can change the color or text but viewHolder.layout.addView(textView) doesn't do anything . And why view size doesn't change?

enter image description here enter image description here

public class StackAdapter extends BaseAdapter...
...
public View getView...
final ViewHolder viewHolder;
...
viewHolder.layout = (LinearLayout) convertView.findViewById(R.id.telephone_1);
...
    viewHolder.layout.post(new Runnable() {
                    @Override
                    public void run() {
                        TextView textView = (TextView)viewHolder.layout.findViewById(R.id.textView11);
                        textView.setText("din1");
                        textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 22);

    //or
                        TextView textView2 = (TextView)viewHolder.layout.findViewById(R.id.textView22);
                        textView2.setText("din2");
                        textView2.setTextSize(TypedValue.COMPLEX_UNIT_SP, 22);
                        int height_in_pixels2 = textView2.getLineCount() * textView2.getLineHeight(); //approx height text
                        textView2.setHeight(height_in_pixels2);

                    }
                });

xml

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




    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:background="@android:drawable/dialog_holo_light_frame"
        android:id="@+id/card_1"
        android:layout_marginTop="6dp"
        android:layout_marginBottom="60dp"
        android:layout_marginLeft="6dp"
        android:layout_marginRight="6dp"
        android:padding="20dp">

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:weightSum="1"
            android:gravity="top">

            <LinearLayout
                android:orientation="vertical"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:foregroundGravity="left"
                android:gravity="left"
                android:layout_gravity="left">

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="50dp"
                    android:id="@+id/imageViewLogoUrl_1"
                    android:foregroundGravity="left"
                    android:scaleType="fitStart"
                    />
            </LinearLayout>

            <android.support.percent.PercentFrameLayout
                xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:app="http://schemas.android.com/apk/res-auto"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center"
                android:orientation="vertical"
                >
            <LinearLayout
                app:layout_heightPercent="65%"
                android:id="@+id/main_telephone_1"
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="#5191bb">

                <LinearLayout
                    android:id="@+id/telephone_1"
                    android:orientation="vertical"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_weight="0.8"
                    android:layout_marginRight="8dp"
                    android:layout_marginTop="5dp">

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="Hello"
                        android:id="@+id/textView11"/>
                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="Hello"
                        android:id="@+id/textView22"/>

                </LinearLayout>

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

                    <TextView
                        android:id="@+id/textViewCompanyName_1"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:gravity="right"
                        android:textSize="24sp"
                        android:text="Organization"
                        android:singleLine="true"
                        android:layout_marginBottom="-4dp"/>

                    <TextView
                        android:id="@+id/textViewFullName_1"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:gravity="right"
                        android:textSize="20sp"
                        android:text="Full Name User"
                        android:singleLine="true"
                        android:layout_marginBottom="-4dp"/>

                    <TextView
                        android:id="@+id/textViewJobTitle_1"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:textSize="20sp"
                        android:text="Job Title"
                        android:gravity="right"
                        android:singleLine="true"
                        android:layout_marginBottom="-4dp"/>

                    <TextView
                        android:id="@+id/textViewDepartment_1"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:textSize="20sp"
                        android:text="Department"
                        android:gravity="right"
                        android:singleLine="true"
                        android:layout_marginBottom="-4dp"/>
                </LinearLayout>
            </LinearLayout>

            <LinearLayout
                android:layout_alignParentBottom="true"
                app:layout_marginTopPercent="65%"
                android:id="@+id/information_1"
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="#cc6b6b">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:text="Small Text"
                    android:id="@+id/textView2"/>
            </LinearLayout>
        </android.support.percent.PercentFrameLayout>

        </LinearLayout>

    </LinearLayout>



</RelativeLayout>

Upvotes: 0

Views: 1672

Answers (1)

sushildlh
sushildlh

Reputation: 9056

this is work for my project

 textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textView.getTextSize() + 3.0f);

and enjoy coding ......

for changing the height or width use this ....

  LinearLayout.LayoutParams linearPrams = new   LinearLayout.LayoutParams(LayoutParam.WRAP_CONTENT,LayoutParam.WRAP_CONTENT);

    textView.setLayoutParams(linearPrams);

PercentFrameLayout all linear layout should be in percentage manner ......

<android.support.percent.PercentFrameLayout
         xmlns:android="http://schemas.android.com/apk/res/android"
         xmlns:app="http://schemas.android.com/apk/res-auto"
         android:layout_width="match_parent"
         android:layout_height="match_parent">
     <LinearLayout
         app:layout_widthPercent="50%"
         app:layout_heightPercent="50%"
         app:layout_marginTopPercent="25%"
         app:layout_marginLeftPercent="25%"/>
 </android.support.percent.PercentFrameLayout/>

Upvotes: 1

Related Questions