2016-04-20 12 views
0

Die Schriftgröße wird geändert, aber die andere Ansicht wird nicht verschoben. Ich kann in diesem Layout keine Elemente hinzufügen. Ich kann nur vorhandene Ansicht ändern, zum Beispiel kann ich die Farbe oder den Text ändern, aber viewHolder.layout.addView(textView) tut nichts. Und warum view Größe ändert sich nicht?Kann die Größe von TextView nicht ändern

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

versuchen müssen, das Layout Gewicht –

Antwort

1

das ist Arbeit für mein Projekt

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

und genießen Codierung ......

für die Höhe oder Breite Verwendung Ändern dieses ....

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

    textView.setLayoutParams(linearPrams); 

PercentFrameLayout alle linearen Layout in Prozent Weise sein sollte ......

<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

zu entfernen Hallo Kumar, tut mir leid, aber es funktioniert nicht :(Schrift erhöht. Aber die 'tekstView' nicht ändern –

+1

Bitte beachten Sie die Antwort bearbeiten – sushildlh

+1

und entfernen Sie einfach die" android: layout_weight "von Ihnen xml – sushildlh

Verwandte Themen