Note that there are some explanatory texts on larger screens.

plurals
  1. POobtaining android layout parameter 'MATCH_PARENT' actual value
    primarykey
    data
    text
    <p>I have an xml layout which places an image at the top of the screen, and some text at the bottom. In between the two I have a Gallery widget which I populate with images all of the same size</p> <p>The reasoning for this, is that I can call <code>.setLayoutParams(new Gallery.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)</code> and the gallery images will fit the space inbetween the image and text perfectly.</p> <p>The problem I am having is that I don't want the images to get too large. For small resolutions, filling the parent is good. When the resolutions increase, the images become too large and I need a 'cap' of around 200-300 dp.</p> <p>Is there a way to obtain the integer value of the LayoutParam.MATCH_PARENT? then I can perform a comparison and limit the size.</p> <p>edit - code</p> <p></p> <pre><code> &lt;ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/chooseanimage" /&gt; &lt;RelativeLayout android:id="@+id/rlayout1" android:layout_width="wrap_content" android:layout_height="wrap_content"&gt; &lt;com.google.ads.AdView android:id="@+id/adView" android:layout_width="wrap_content" android:layout_height="50dp" ads:adUnitId="--" ads:adSize="BANNER" ads:testDevices="TEST_EMULATOR,00" ads:loadAdOnCreate="true" android:layout_centerHorizontal="true" android:layout_alignParentBottom="true" /&gt; &lt;Gallery android:id="@+id/gallery" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_below="@id/imageView1" android:layout_above="@id/adView" /&gt; &lt;/RelativeLayout&gt; &lt;/LinearLayout&gt; </code></pre> <p>and java</p> <pre><code>public View getView(int position, View convertView, ViewGroup parent) { if( !(convertView instanceof ImageView)){ convertView = new ImageView(this.myContext); convertView.setLayoutParams(new Gallery.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT)); convertView.setBackgroundResource(imageBackground); ((ImageView) convertView).setScaleType(ImageView.ScaleType.FIT_XY); } ((ImageView) convertView).setImageResource(this.myImageIds[position]); return convertView; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload