Android Layout; Image takes entire screen -
i trying fill activity 2 views, imageview
on left side, , textview
on right. image should sized fill entire vertical space. text should occupy whatever space left over. after watching few tutorials, seems need linearlayout
horizontal orientation, , textview
's layout_weight
property positive integer.
this have far:
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingbottom="@dimen/activity_vertical_margin" tools:context=".mainactivity"> <imageview android:id="@+id/imageview" android:layout_width="wrap_content" android:layout_height="match_parent" android:src="@drawable/charsheet" /> <textview android:id="@+id/ipsum" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="1" android:text="@string/ipsum" /> </linearlayout>
the problem is, however, image, creates white space left , right fills entire screen. there no room left textview
.
i tried using relativelayout
imageview
's tostartof
property set id of textview
, text fills entire screen instead.
i wouldn't have thought such complicated thing do, when set out make activity, here are. appreciated.
i think thing you're missing adjustviewbounds on imageview. try this:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" > <imageview android:id="@+id/imageview" android:layout_width="wrap_content" android:layout_height="match_parent" android:scaletype="fitstart" android:adjustviewbounds="true" android:src="@drawable/doug" /> <textview android:id="@+id/ipsum" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:text="ipsum" /> </linearlayout>
without adjustimagebounds, imageview takes more space needs display image.
the above layout creates preview in android studio looks me:
Comments
Post a Comment