2016-04-20 11 views
0

フォントサイズは変更されますが、他のビューは移動しません。私はこのレイアウトで任意の要素を追加することはできません。私は既存のビューのみを変更することができます。例えば、色やテキストを変更することはできますが、viewHolder.layout.addView(textView)は何もしません。なぜviewサイズは変わらないのですか?TextViewの文字サイズの変更

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> 
+0

は、レイアウトの重みを削除しようとする必要が –

答えて

1

これは

......私のプロジェクト

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

とコーディング楽しむための作品です

は、すべての線形レイアウトが割合的にする必要があり、高さや幅の使用この....

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

    textView.setLayoutParams(linearPrams); 

PercentFrameLayoutを変更するための......

<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/> 
+0

こんにちはクマール、申し訳ありませんが動作しません:(フォントが増加しました。しかし、 'tekstView'は変更されません –

+1

編集の回答 – sushildlh

+1

を見て、あなたからxml – sushildlh