Layout TextView重力=”;top";但动态更改字体大小不会';t保持文本与顶部对齐
我有一个应用程序,需要在图像的某些位置上动态对齐文本视图。图像缩放以适应视图。文本条目由用户添加。我使用相对长度和边距来正确定位文本。一切都很好 当用户旋转屏幕时,我使用OnRetainOnConfiguration Instance()保存文本位置和位图。重新创建视图时,我将视图添加回RelativeLayout。现在,由于视图的大小不同,图像的比例也不同。为了使文本框保持在同一位置,我必须考虑到这一点。我有所有的代码工作,除了一个问题 如果我创建一个TextView并将fontSize设置为一个小尺寸(例如。Layout TextView重力=”;top";但动态更改字体大小不会';t保持文本与顶部对齐,layout,text,textview,alignment,font-size,Layout,Text,Textview,Alignment,Font Size,我有一个应用程序,需要在图像的某些位置上动态对齐文本视图。图像缩放以适应视图。文本条目由用户添加。我使用相对长度和边距来正确定位文本。一切都很好 当用户旋转屏幕时,我使用OnRetainOnConfiguration Instance()保存文本位置和位图。重新创建视图时,我将视图添加回RelativeLayout。现在,由于视图的大小不同,图像的比例也不同。为了使文本框保持在同一位置,我必须考虑到这一点。我有所有的代码工作,除了一个问题 如果我创建一个TextView并将fontSize设置为
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="0dp"
>
<com.xyx.ScalableLayout
android:id="@+id/layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="0dp"
android:clickable="true"
android:gravity="top"
>
<com.xyx.ScaledImageView
android:id="@+id/formView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="0dp"
/>
<com.xyx.ScalableLayout>
</ScrollView>
textView = new TextView(getContext());
textView.setPadding(0, 0, 0, 0);
textView.setSingleLine();
textView.setFocusableInTouchMode(false);
textView.setClickable(false);
textView.setGravity(Gravity.TOP);
textView.setText(entry.mText);
float fontSize = mImageView.mapSizeToView(entry.mPointSize);
textView.setTextSize(TypedValue.COMPLEX_UNIT_PT, fontSize);
params = new RelativeLayout.LayoutParams(
ViewGroup.MarginLayoutParams.WRAP_CONTENT,
ViewGroup.MarginLayoutParams.WRAP_CONTENT);
params.leftMargin = Math.round(viewLoc.x);
params.topMargin = Math.round(viewLoc.y);
addView(textView, params);
float fontSize = mImageView.mapSizeToView(entry.mPointSize);
textView.setTextSize(TypedValue.COMPLEX_UNIT_PT, fontSize);
PointF viewLoc = computeTopLeft(entry, entry.mTextView.getPaint());
params = (RelativeLayout.LayoutParams) textView.getLayoutParams();
params.leftMargin = Math.round(viewLoc.x);
params.topMargin = Math.round(viewLoc.y);
textView.setLayoutParams(params);
textView.forceLayout();