1
最近我對ImageView對齊問題感到困惑。我們知道ImageView的寬度是而不是正是實際圖像的寬度(因爲有時圖像被縮放)。那麼如何將文本視圖與的實際圖像的邊界對齊,而不是ImageView?將textview對齊圖像的實際邊界
+----------------------------------------+
| +--------------+ |
| ImageView | Scaled Image | |
| +--------------+ |
+----------------------------------------+
| I want to align my textview to here
| Not here
下面的代碼不符合我的要求,它總是TextView的對齊到的ImageView的權利,而不是實際的圖像:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<ImageView
android:id="@+id/mypic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/mypic" />
<TextView
android:id="@+id/mytext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/mypic" />
</RelativeLayout>
非常感謝!
您需要scaletype,使其始終設置爲您的ImageView適合imageview。我不認爲你可以根據縮放的圖像設置你的textview(它對圖像不同) – Dhina
請參閱'ImageView#getImageMatrix'和'ImageView#getDrawable'方法,然後仔細閱讀'Matrix' API – pskink