Reputation: 65
I have two linear layouts placed side by side. The right side layout contains an image strip. The problem is the image does not start from top, there is unwanted bottom margin appearing as well, creating unnecessary scrolling. Best would be if there is no unnecessary scrolling at all. There are more buttons at the left side. Right side image may be clipped.
Here is my code
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:layout_weight="2"
android:orientation="vertical" >
<TextView
android:id="@+id/textViewCaption"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:text="This is my Application"
android:textSize="40sp" />
<Button
android:id="@+id/btnOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00FFFFFF"
android:text="Button One"
android:textSize="@dimen/home_sub_caption_height" />
<Button
android:id="@+id/btnTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00FFFFFF"
android:text="Button Two"
android:textSize="25sp" />
<Button
android:id="@+id/btnThree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00FFFFFF"
android:text="Button Three"
android:textSize="25sp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="0dp"
android:layout_weight="1">
<ImageView
android:id="@+id/imageViewLogo"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@drawable/qutub" />
</LinearLayout>
</LinearLayout>
</ScrollView>
Upvotes: 0
Views: 387
Reputation: 492
in the ImageView use android:layout_height="wrap_content"
instead of android:layout_height="match_parent"
I guess it would work for you.
Upvotes: 1
Reputation: 327
Try it set Imageview
layout_gravity="top"
and layout_height="wrap_content"
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="3">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:orientation="vertical">
<TextView
android:id="@+id/textViewCaption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:text="This is my Application"
android:textSize="40sp" />
<Button
android:id="@+id/btnOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00FFFFFF"
android:text="Button One"
android:textSize="25sp" />
<Button
android:id="@+id/btnTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00FFFFFF"
android:text="Button Two"
android:textSize="25sp" />
<Button
android:id="@+id/btnThree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00FFFFFF"
android:text="Button Three"
android:textSize="25sp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<ImageView
android:id="@+id/imageViewLogo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/qutub"
android:layout_gravity="top"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
Upvotes: 0
Reputation: 140
Add this attribute in ImageView
android:scaleType="fitStart"
Hope this helps!
Upvotes: 0
Reputation: 376
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:layout_weight="2"
android:orientation="vertical" >
<TextView
android:id="@+id/textViewCaption"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:text="This is my Application"
android:textSize="40sp" />
<Button
android:id="@+id/btnOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00FFFFFF"
android:text="Button One"
/>
<Button
android:id="@+id/btnTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00FFFFFF"
android:text="Button Two"
android:textSize="25sp" />
<Button
android:id="@+id/btnThree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00FFFFFF"
android:text="Button Three"
android:textSize="25sp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="0dp"
android:layout_weight="1">
<ImageView
android:id="@+id/imageViewLogo"
android:layout_width="250dp"
android:layout_height="250dp"
android:layout_weight="1"
android:src="@drawable/profile" />
</LinearLayout>
</LinearLayout>
</ScrollView>
Upvotes: 0
Reputation: 5301
If you don't need scroll then remove the ScrollView
<?xml version="1.0" encoding="utf-8"?><?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">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:layout_weight="2"
android:orientation="vertical">
<TextView
android:id="@+id/textViewCaption"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:text="This is my Application"
android:textSize="40sp" />
<Button
android:id="@+id/btnOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00FFFFFF"
android:text="Button One" />
<Button
android:id="@+id/btnTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00FFFFFF"
android:text="Button Two"
android:textSize="25sp" />
<Button
android:id="@+id/btnThree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00FFFFFF"
android:text="Button Three"
android:textSize="25sp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="0dp"
android:layout_weight="1">
<ImageView
android:id="@+id/imageViewLogo"
android:layout_width="match_parent"
android:scaleType="fitXY"
android:layout_height="match_parent"
android:src="@drawable/profile" />
</LinearLayout>
</LinearLayout>
Upvotes: 0