Note that there are some explanatory texts on larger screens.

plurals
  1. POAdjust view width and height to 50%
    primarykey
    data
    text
    <p>I'm creating a gallery with custom adapter (a relative layout in witch i place an imageview as a thumbnail, a textview as Name and other staff).</p> <p>The gallery displays in fullscreen perfectly, but this is not what i want.. i want the custom relative layout to be scaled to 50% in height and width relatively to the screen size. I tried this : </p> <pre><code>gallery.getLayoutParams().width = relativelayout.getWidth() / 2; gallery.getLayoutParams().height = relativelayout.getHeight() / 2; </code></pre> <p>This was a wrong try, it just set the height and width to the correct size without scaling the content.</p> <p>This is the original view :</p> <p><img src="https://i.stack.imgur.com/lIuNz.png" alt="Original"></p> <p>This is what i've expected :</p> <p><img src="https://i.stack.imgur.com/kGzuL.png" alt="Expectation"></p> <p>And this is what i've got : </p> <p><img src="https://i.stack.imgur.com/sX20j.png" alt="Result"></p> <p>This is the layout Cover : </p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" &gt; &lt;ImageView android:id="@+id/ivTourCover" android:layout_width="640dp" android:layout_height="240dp" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:contentDescription="@string/app_name" android:scaleType="fitXY" android:src="@drawable/croppedstopgallery_f45d88e4_7864_4dbc_9123_ad7953d8724a" /&gt; &lt;ImageButton android:id="@+id/ivHorizontalLine" android:layout_width="match_parent" android:layout_height="1dp" android:layout_below="@+id/tvTourName" android:layout_marginLeft="20dp" android:layout_marginRight="20dp" android:layout_marginTop="0dp" android:contentDescription="@string/app_name" android:scaleType="fitXY" android:src="@drawable/horizontal_line" /&gt; &lt;TextView android:id="@+id/tvAuthorName" style="@style/Cover.AuthorName" android:layout_width="fill_parent" android:layout_height="19dp" android:layout_alignTop="@+id/ivAuthorThumbnail" android:layout_marginLeft="12dp" android:layout_marginRight="17dp" android:layout_toLeftOf="@+id/ivGo" android:layout_toRightOf="@+id/ivAuthorThumbnail" android:text="Anna Greenleaf" /&gt; &lt;ImageView android:id="@+id/ivAuthorThumbnail" android:layout_width="46dp" android:layout_height="46dp" android:layout_alignLeft="@+id/ivHorizontalLine" android:layout_below="@+id/ivHorizontalLine" android:layout_marginTop="20dp" android:contentDescription="@string/app_name" android:scaleType="fitXY" android:src="@drawable/croppedstopgallery_f45d88e4_7864_4dbc_9123_ad7953d8724a" /&gt; &lt;ImageView android:id="@+id/ivGo" android:layout_width="46dp" android:layout_height="46dp" android:layout_alignRight="@+id/ivHorizontalLine" android:layout_alignTop="@+id/tvAuthorName" android:contentDescription="@string/app_name" android:scaleType="fitXY" android:src="@drawable/tour_cover_go" /&gt; &lt;TextView android:id="@+id/tvAuthorDescription" style="@style/Cover.AuthorDescription" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/tvAuthorName" android:layout_alignRight="@+id/tvAuthorName" android:layout_below="@+id/tvAuthorName" android:text="London native and London over!" /&gt; &lt;SurfaceView android:id="@+id/svFooter" android:layout_width="wrap_content" android:layout_height="30dp" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:layout_alignParentRight="true" android:background="@color/CoverFooter" /&gt; &lt;TextView android:id="@+id/tvFooterText" style="@style/Cover.FooterText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/svFooter" android:layout_alignBottom="@+id/svFooter" android:layout_centerHorizontal="true" android:layout_marginBottom="10dp" android:text="Individual" /&gt; &lt;com.example.zipdownload.utilities.ui.AutoResizeTextView android:id="@+id/tvTourName" style="@style/Cover.TourName" android:layout_width="wrap_content" android:layout_height="79dp" android:layout_below="@+id/ivTourCover" android:layout_centerHorizontal="true" android:layout_marginLeft="20dp" android:layout_marginRight="20dp" android:layout_marginTop="15dp" android:gravity="center|top" android:text="Beautiful London in Winston Churchill&amp;apos;s footsteps" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>The View Gallery : </p> <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/rlGallery" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".Gallery" &gt; &lt;Gallery android:id="@+id/gCoverflow" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:gravity="top" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>And the Activity Gallery : </p> <pre><code>public class Gallery extends Activity { private android.widget.Gallery gCoverflow; private RelativeLayout rlGallery; private CoverAdapter adapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_gallery); rlGallery = (RelativeLayout) findViewById(R.id.rlGallery); adapter = new CoverAdapter(this); gCoverflow = (android.widget.Gallery) findViewById(R.id.gCoverflow); gCoverflow.setAdapter(adapter); } @Override public void onWindowFocusChanged(boolean hasFocus) { super.onWindowFocusChanged(hasFocus); gCoverflow.getLayoutParams().width = rlGallery.getWidth() / 2; gCoverflow.getLayoutParams().height = rlGallery.getHeight() / 2; } } </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.
 

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