I am developing an application for Android that displays pictures of animals in ImageView in PageViewer. On most of the phones, everything seems fine. However, on my S7 (display resolution higher than the resolution of the picture), I can't get the picture to stretch to expand the device width.
The imageView also has a Xamarin photoView attacher attached to it, however I don't think it has any effect. I tried to remove it and it's still the same.
I already tried android:adjustViewBounds and all android:scaleType and unfortunately it didn't help.
Here is my xml code:
Part of the activity xml:
<fieldguideapp.droid.MyViewPager
android:id="#+id/pagerAnimalProfile"
android:layout_width="match_parent"
android:background="#000000"
android:layout_height="wrap_content" />
PagerLayout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:id="#+id/imgPagerLayoutImageView" />
<RelativeLayout
android:id="#+id/relLayoutImgPagerImageDesc"
android:orientation="horizontal"
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="wrap_content"
android:background="#FFFFFFFF"
android:layout_gravity="bottom">
<TextView
android:text="Image desc"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FFFFFFFF"
android:textColor="#FF000000"
android:id="#+id/txtImgPagerImageDescription"
android:layout_alignParentLeft="true" />
<LinearLayout
android:id="#+id/linLayoutImgPagerIndicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_centerHorizontal="true"
android:layout_alignBottom="#id/txtImgPagerImageDescription" />
<TextView
android:text="Image credit"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FFFFFFFF"
android:textColor="#FF000000"
android:id="#+id/txtImgPagerImageCredit"
android:layout_alignParentRight="true"
android:layout_alignBottom="#id/linLayoutImgPagerIndicator" />
</RelativeLayout>
</LinearLayout>
Part of code that changes the height of the pager:
// To specify the height of the pager, select the highest child
protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
int height = 0;
for (int i = 0; i < ChildCount; i++)
{
View child = GetChildAt(i);
child.Measure(widthMeasureSpec, MeasureSpec.MakeMeasureSpec(0, MeasureSpecMode.Unspecified));
int h = child.MeasuredHeight;
if (h > height) height = h;
}
if (Resources.Configuration.Orientation == Android.Content.Res.Orientation.Portrait)
{
heightMeasureSpec = MeasureSpec.MakeMeasureSpec(height, MeasureSpecMode.Exactly);
}
base.OnMeasure(widthMeasureSpec, heightMeasureSpec);
}
EDIT: Here is what I get:
I would appreciate any kind of help or advice. Thanks
I eventually resized the picture manually using Bitmap.CreateScaledBitmap() method to fit the screen dimensions and then set it using ImageView.SetImageDrawable() and it works perfectly. I need to call GC.Collect() before and after in order to avoid OutOfMemoryException.
Although this isn't ideal, it works.
Related
I am trying to display a table that has three rows. The first two are images, the third is just data. I have tried to set them up with table row weights of 45%, 45%, 10%... However that never happens, it always come out somewhere about 47%, 47%, 6%.
But that's minor compared to the behavior that I can't figure out.
The images and data come in async, so they are populated using a "runnable".
The problem is the first image gets bigger every time it updates. And the second image keeps getting smaller.
However, here's the kicker, when I set breakpoints and pause it to debug it, it works exactly as I want it to. It doesn't change sizes, the row heights do not change.
So, that said, here is my layout XML:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="0dp"
android:paddingBottom="0dp"
android:layout_weight="1"
android:id="#+id/mainscreen">
android:background="#00ff00"
<TableRow
android:layout_width="fill_parent"
android:layout_height="0dp"
android:id="#+id/img1box"
android:layout_weight="45"
android:gravity="center_vertical|center_horizontal">
<ImageView
android:contentDescription="image1"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="#+id/img1"
android:src="#drawable/icon"/>
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="0dp"
android:id="#+id/img2box"
android:layout_weight="45"
android:gravity="center_vertical|center_horizontal">
<ImageView
android:contentDescription="image2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/img2"
android:src="#drawable/icon" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="10"
android:id="#+id/dataholder"
android:gravity="center_vertical|center_horizontal">
<TextView
android:id="#+id/statusbox"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
android:textColor="#000000"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_gravity="center"/>
</TableRow>
</TableLayout>
I have tried settings such as 0dp (or 0px), fill_parent, match_parent, wrap_content, and a dozen other configurations from web searches.
And the code snippets that happen when the data/images are posted (removed the parts that do stuff like findViewById(), that happens at onCreate() and works fine, plus rename some confidential variables):
final Runnable HandleImage1Ready = new Runnable() {
#Override
public void run() {
int height, width;
float xfactor, yfactor;
height = m_Image1Box.getHeight(); // This is the TableRow
width = m_Image1Box.getWidth();
// Compute the reduction factor, but it's
// always by height right now, so we just use that
Bitmap image = BitmapFactory.decodeByteArray(m_img1, 0, m_img1.length);
yfactor = height / (float) image.getHeight();
xfactor = width / (float) image.getWidth();
// create a new bitmap, I even try reducing the "height"
// to prevent the table row from growing... doesn't help
Bitmap scaled = Bitmap.createScaledBitmap(image, (int) (image.getWidth() * yfactor), height, true);
m_Image1.setImageBitmap(scaled);
CompleteProcessing();
}
};
final Runnable HandleImage2Ready = new Runnable() {
#Override
public void run() {
int height, width;
float xfactor, yfactor;
height = m_Image2Box.getHeight(); // This is the TableRow
width = m_Image2Box.getWidth();
// EVEN TRY USING THE SAME IMAGE ON ROW 2...
//Bitmap image = BitmapFactory.decodeByteArray(m_img2, 0, m_img2.length);
Bitmap image = BitmapFactory.decodeByteArray(m_img1, 0, m_img1.length);
yfactor = height / (float) image.getHeight();
xfactor = width / (float) image.getWidth();
Bitmap scaled = Bitmap.createScaledBitmap(image, (int) (image.getWidth() * yfactor), height, true);
m_Image2.setImageBitmap(scaled);
CompleteProcessing();
}
};
final Runnable HandleMicrReady = new Runnable() {
#Override
public void run() {
int height, width;
// Just to debug these, and see how this row changes
height = m_statusBox.getHeight();
width = m_statusBox.getWidth();
m_statusBox.setText(m_data);
CompleteProcessing();
}
};
Repeating... When I set a break point in one of the above functions, and resume the execution, both images are the same size, every time it posts new images. Which is what I want to happen.
But if I don't set the break point, every time a new image is posted, the top table row gets bigger and bigger. To the point that the top image is over 50% of the table (screen), and the bottom image and table row of data are getting smaller.
In essence, I believe Android Studio is laughing at me because, like a rattle in a car you take in, it doesn't do it when someone is watching for the problem...
(I included an "android-studio" tag, because pausing it in AS debugger causes the problem it disappear).
Any advice is appreciated.
-Scotty
Table layouts do not seem to take the weights placed upon them very strictly. E.g. when you add an ImageView to a TableRow with or without a src it already renders slightly differently. I also verified this with 2 images with different dimensions and the row with the bigger image completely overtakes the row of the smaller one.
The solution is to not use a TableLayout. If you don't want to use something like a GridView I suggest sticking with LinearLayout. You can use it in the exact same manner. You only need to specify its android:orientation="horizontal|vertical" attribute instead of making a distinction between TableRow (the horizontal kind) or TableLayout (the vertical kind)
Here's a visual comparison:
So for your provided layout XML this would become:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="0dp"
android:paddingBottom="0dp"
android:weightSum="100"
android:background="#00ff00"
android:id="#+id/mainscreen">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:id="#+id/img1box"
android:layout_weight="45"
android:gravity="center_vertical|center_horizontal">
<ImageView
android:contentDescription="image1"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="#+id/img1"
android:src="#drawable/icon"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:id="#+id/img2box"
android:layout_weight="45"
android:gravity="center_vertical|center_horizontal">
<ImageView
android:contentDescription="image2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/img2"
android:src="#drawable/icon" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="10"
android:id="#+id/dataholder"
android:gravity="center_vertical|center_horizontal">
<TextView
android:id="#+id/statusbox"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
android:textColor="#000000"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_gravity="center"/>
</LinearLayout>
</LinearLayout>
Is it possible that a view should make it height same as it's width?
or any other layout for this purpose, because for vector image it's compulsory to provide width and height.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/googleLoginBtn"
android:orientation="horizontal"
android:layout_centerVertical="true">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<ImageView
android:layout_width="fill_parent"
android:layout_height="<height should be equal to the width>"
app:srcCompat="#drawable/simple"
tools:ignore="MissingPrefix"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Snappy"
android:textColor="#FF4081"
android:textSize="30dp"
android:singleLine="true"
android:gravity="center"
android:layout_margin="10dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Type less, do more. Fastest way to transfer money & make other transactions."
android:layout_margin="10dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="#drawable/simple"
tools:ignore="MissingPrefix"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Smart"
android:textColor="#FF4081"
android:textSize="30dp"
android:gravity="center"
android:layout_margin="10dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Type less, do more. Fastest way to transfer money & make other transactions."
android:layout_margin="10dp"/>
</LinearLayout>
</LinearLayout>
Update:
I would use a ConstraintLayout today and use the property app:layout_constraintDimensionRatio="1:1"
Old Answer:
It's not possible entirely in xml without using a custom ImageView. This would be a solution:
public class SquareImageView extends ImageView {
#Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int width = getMeasuredWidth();
setMeasuredDimension(width, width);
}
}
However if your Image is already Square you can use the normal ImageView:
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:adjustViewBounds="true" />
A third solution would be setting the width and height directly in your Code:
LayoutParams params = imageView.getLayoutParams();
params.height = params.width ;
imageView.setLayoutParams(params);
You should be able to use the Percent support library for this.
You can either replace the LinearLayout the ImageViewis inside of with a PercentRelativeLayout and have the other views android:layout_belowor wrap the ImageView in a PercentFrameLayout.
I'm going to assume you've already defined the app namespace in this file as xmlns:app="http://schemas.android.com/apk/res-auto" since I see you using the namespace.
Once you've included the appropriate support library, the PercentFrameLayout approach would look something like this:
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<android.support.percent.PercentFrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="fill_parent"
app:layout_aspectRatio="100%"
app:srcCompat="#drawable/simple"
tools:ignore="MissingPrefix"/>
</android.support.percent.PercentFrameLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Snappy"
android:textColor="#FF4081"
android:textSize="30dp"
android:singleLine="true"
android:gravity="center"
android:layout_margin="10dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Type less, do more. Fastest way to transfer money & make other transactions."
android:layout_margin="10dp"/>
</LinearLayout>
Just a little update: The PercentFrameLayout class was deprecated in API level 26.1.0. Consider using ConstraintLayout and associated layouts instead. More information here: https://developer.android.com/reference/android/support/percent/PercentFrameLayout
use this
#Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int parentHeight = MeasureSpec.getSize(heightMeasureSpec);
int myWidth = (int) (parentHeight * 0.5);
super.onMeasure(MeasureSpec.makeMeasureSpec(myWidth, MeasureSpec.EXACTLY), heightMeasureSpec);
}
I'm facing an issue with an xml layout.
This is the full xml:
<FrameLayout
android:id="#+id/root"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="match_parent">
<ImageView
android:id="#+id/image"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:adjustViewBounds="true"
tools:src="#drawable/segment_cultura"/>
<LinearLayout
android:id="#+id/message_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#color/black_divider"
android:padding="4dp">
<TextView
android:id="#+id/message"
style="#style/TextAppearance.AppCompat.Caption"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ellipsize="end"
android:maxLines="2"
android:textColor="#color/white_secondary_text"
/>
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="end"
android:src="#drawable/ic_message"/>
</LinearLayout>
<ImageView
android:id="#+id/cancel"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="top|end"
android:layout_margin="4dp"
android:src="#drawable/ic_close"/>
</FrameLayout>
The goal: Use this as an item in a fixed height horizontal RecyclerView, using ONLY the image to determine the size of the item. Other views, such message_container or cancel will need to adapt to this size.
The problem: message_container needs to fill the width of the item, but it shouldn't modify the item width when there is a long text in message. It should go to the 2nd line and then get ellipsized. What happens instead is message never goes to the second line and makes the parents (message_container and root) enlarge to fit its text.
I'm looking for a solution that only involves xml, if I can't find it a custom view is preferred to some logic in the adapter.
Thank you for your time.
I solved this by using:
image.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
if (root != null && image.getWidth() != 0)
root.getLayoutParams().width = image.getWidth();
});
I have a listview, and one list item consist of two textview's and an imageview(actual image is downloaded from server with help of ION library). I want to fit exactly 3 list items on the screen, but as screen resolutions vary I cant do it simply with setting item height.
What i've tried is:
vi_params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, (int)(MainActivity.screenHeight*0.33));
userImage.setLayoutParams(vi_params);
But this gives event different result - no image is shown at all.
This is how my list_item.xml looks like.
<RelativeLayout
android:id="#+id/widget32"
android:layout_width="fill_parent"
android:layout_height="110dp"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_x="0dp"
android:layout_y="0dp">
<ImageView
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="260dp"
android:layout_x="0dp"
android:layout_y="0dp"
android:scaleType="fitXY"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/ID"
android:layout_width="320dp"
android:layout_height="wrap_content"
android:visibility="invisible"/>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:text="TextView" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="10dp"
android:layout_marginRight="10dp"
android:text="TextView" />
</RelativeLayout>
So, any ideas how to make list item height depending on screen height, so only three would fit?
So, just as I thought, multiplying integer by 0.33 was returning 0, so i used DIVISION:
"userImage.getLayoutParams().height = MainActivity.height / 3;
Anyways, i still don't get wanted result, because actionBar still takes place.
So i just got it with:
TypedValue tv = new TypedValue();
if (getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true))
{
actionbarheight = TypedValue.complexToDimensionPixelSize(tv.data,getResources().getDisplayMetrics());
}
And still it wasnt perfect, so i got myself height of titlebar:
public int getStatusBarHeight() {
int result = 0;
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
result = getResources().getDimensionPixelSize(resourceId);
}
return result;
}
I have such layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/my_image"
android:ellipsize="end"
android:singleLine="true"
android:text="Some text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView
android:id="#+id/my_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/title"
android:layout_alignBottom="#+id/title"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:adjustViewBounds="true"
android:src="#drawable/my_bitmap_image" />
This layout does almost what I need: it makes image view height the same as text view. The image graphic contents stretched also keeping aspect ratio.
But, the width of the image view does not change! As a result, I have a wide gap between text and the image view! As a temporal solution, I override View#onLayout.
The question: how to change image width in xml layout?
UPDATE:
This is a final layout I need (text + a few images).
Look at the first image: its width should be exactly the same as scaled image in it with no paddings and margins:
For the imageView you can add the images to a linearlayout and give the weight property. For example if you have 3 images then give the linearlayout weight as 3 and then for each image you give the weight as 1. This way it will be uniformly aligned with equal width for all the images. Make linear orientation as horizontal hope so u got my point.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="3"
>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight ="1" />
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight ="1" />
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight ="1" />
</LinearLayout>
OK, as I see from the answers, there is no solution to force image views to change theirs width and height proportionally.
So, this can be solved only programmatically.
There is my solution below :
a) Create you custom layout class
(don't forget to override all the parent constructors with public access modifier, otherwise GUI editor will fail):
public class MyLayout extends RelativeLayout {...
b) Override method: Deprecated - changing layout params in this method might cause side effects. See recommended approach below
protected void onLayout(boolean changed, int l, int t, int r, int b) {
ImageView icon = (ImageView) findViewById(R.id.my_image);
icon.setMaxWidth(icon.getMeasuredHeight());
super.onLayout(changed, l, t, r, b);
}
b) Add creational method:
public static MyLayout createLayout(ViewGroup parent) {
Context context = parent.getContext();
MyLayout item = (MyLayout) LayoutInflater.from(context).inflate(
R.layout.my_layout, parent, false);
TextView tv = (TextView) findViewById(R.id.title);
ImageView icon = (ImageView) findViewById(R.id.my_image);
ViewGroup.LayoutParams p = icon.getLayoutParams();
p.width = (int) tv.getTextSize();;
icon.setLayoutParams(p);
return item;
}
c) Final layout:
<?xml version="1.0" encoding="utf-8"?>
<com.mypackage.MyLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/my_image"
android:ellipsize="end"
android:singleLine="true"
android:text="Some text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView
android:id="#+id/my_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/title"
android:layout_alignBottom="#+id/title"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:adjustViewBounds="true"
android:src="#drawable/my_bitmap_image" />
</com.mypackage.MyLayout>
Instead of RelativeLayout, use LinearLayout. You may add "Weight" property to ensure desired spacing.
see the code below
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/logonFormButtons"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:baselineAligned="true"
android:orientation="horizontal">
<TextView
android:id="#+id/logonFormBTLogon"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Some Text"
android:layout_weight="0.5" />
<ImageView
android:id="#+id/logonFormBTCancel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/apk"
android:layout_weight="0.5" />
</LinearLayout>
I guess this has to do with android:layout_alignParentRight="true" for your ImageView. Have you tried layout_toRightOf="#id/title" ?
Also you can try android:scaleType="fitStart" on the ImageView. This should align the image to the top left of the ImageView.
As for me I appreciate to change width or height dinamically in my code using getLayoutParams()... for example
DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int height = displaymetrics.heightPixels;
int wwidth = displaymetrics.widthPixels;
convertPixelsToDp(wwidth, getApplicationContext());
// Toast.makeText(getApplicationContext(), height+ "= "+convertPixelsToDp(height, getApplicationContext()) +
// " " + wwidth+ "= "+convertPixelsToDp(wwidth, getApplicationContext()), Toast.LENGTH_LONG).show();
//scroll view 1 screen height size
scr1 = (ScrollView) findViewById(R.id.ScrollView01);
scr1.getLayoutParams().height=height - 200;
put image view in Linear Layout . the give weight to each and every image view.. it will increase the size proportionately ..
try to add scaleType = fitXY OR centerInside property to imageView