Android 动态排列TextView的边距
我正在使用自定义阵列适配器。我使用的是扩展文本视图,如果文本较大,它会缩小。我的listview项目布局如下Android 动态排列TextView的边距,android,textview,Android,Textview,我正在使用自定义阵列适配器。我使用的是扩展文本视图,如果文本较大,它会缩小。我的listview项目布局如下 <?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_wid
<?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>
问题是,当第一个文本视图变大时,它会出现在该文本视图前面的文本视图上。我只想动态地给texview留出边距,以便它位于底部只需使用LayoutParams即可:
LayoutParams params = new LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT
);
params.setMargins(left, top, right, bottom);
yourbutton.setLayoutParams(params);
根据您使用的布局,您应该使用RelativeLayout.LayoutParams或LinearLayout.LayoutParams。您可以这样做:
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);
试试这个修改过的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>