2014-11-12 3 views
0

Я работаю над пользовательским адаптером Array. Я использую расширенный текст, который сжимается, если текст больше. Мой макет ListView элемент следующегоДинамически упорядочивать поля TextView

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:custom="http://schemas.android.com/apk/res-auto" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="@color/white" 
android:orientation="horizontal" 
android:weightSum="3" > 

<LinearLayout 
    android:id="@+id/textLayout" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_weight="1.8" 
    android:orientation="horizontal" > 

    <LinearLayout 
     android:id="@+id/textLabelLayout" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="10dp" 
     android:layout_marginLeft="10dp" 
     android:layout_marginRight="10dp" 
     android:layout_marginTop="10dp" 
     android:layout_weight="1.0" 
     android:orientation="vertical" > 

     <ft.mobile.client.android.widget.AutoResizeTextView 
      android:id="@+id/accountNameLabel" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:includeFontPadding="false" 
      android:maxLines="1" 
      android:text="ROPL-12345111000" 
      custom:dataType="account" 
      custom:maxLineCount="2" 
      custom:minFontSize="10" 
      custom:preferredLineCount="1" 
      custom:shrinkTextToFit="true" /> 
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/textValueLayout" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:layout_marginBottom="10dp" 
     android:layout_marginLeft="05dp" 
     android:layout_marginRight="05dp" 
     android:layout_marginTop="10dp" 
     android:layout_weight="1.2" 
     android:orientation="horizontal" > 

     <TextView 
      android:id="@+id/accountBalanceLabel" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="right" 
      android:drawableRight="@drawable/drill_down" 
      android:ellipsize="none" 
      android:singleLine="false" 
      android:text="Amount" 
      android:textColor="@color/black" 
      android:textSize="14dp" 
      android:textStyle="bold" /> 
    </LinearLayout> 
</LinearLayout> 

дело в том, что, когда первый взгляд текста больше речь идет над TextView, который присутствует перед этим TextView. Я просто хочу, чтобы динамически дать запас на texview так, что он придет в нижних

ответ

0

Просто используйте LayoutParams сделать так:

LayoutParams params = new LayoutParams(
     LayoutParams.WRAP_CONTENT,  
     LayoutParams.WRAP_CONTENT 
); 
params.setMargins(left, top, right, bottom); 
yourbutton.setLayoutParams(params); 

В зависимости от того, что макета вы используете, вы должны использовать RelativeLayout.LayoutParams или LinearLayout.LayoutParams.

0

Вы можете сделать это так:

TextView tv = (TextView)findViewById(R.id.textview); 
LinearLayout.LayoutParams textViewLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); 
textViewLayoutParams.setMargins(50, 10, 0, 0); 
tv.setLayoutParams(buttonLayoutParams); 
0

Попробуйте этот модифицированный файл XML.

<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:custom="http://schemas.android.com/apk/res-auto" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@color/white" 
    android:orientation="horizontal" 
    android:weightSum="3" > 

     <ft.mobile.client.android.widget.AutoResizeTextView 
       android:id="@+id/accountNameLabel" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_weight=1.8 
       android:includeFontPadding="false" 
       android:maxLines="1" 
       android:text="ROPL-12345111000" 
       custom:dataType="account" 
       custom:maxLineCount="2" 
       custom:minFontSize="10" 
       custom:preferredLineCount="1" 
       custom:shrinkTextToFit="true" /> 


      <TextView 
       android:id="@+id/accountBalanceLabel" 
       android:layout_width="wrap_content" 
       android:layout_weight=1.2 
       android:layout_height="wrap_content" 
       android:layout_gravity="right" 
       android:drawableRight="@drawable/drill_down" 
       android:ellipsize="none" 
       android:singleLine="false" 
       android:text="Amount" 
       android:textColor="@color/black" 
       android:textSize="14dp" 
       android:textStyle="bold" /> 
    </LinearLayout> 
Смежные вопросы