Note that there are some explanatory texts on larger screens.

plurals
  1. POButton resize issue Android
    primarykey
    data
    text
    <p>I have 4 buttons that I want to show in a gridview. I want them to fill the screen as much as possible, but I never made it. I've tried all kind of ScaleTypes and it won't work. Right now I have the scale type in FIT_CENTER but i get an unexpected result. Here's the code I have so far:</p> <p><strong>Main.java</strong></p> <pre><code>@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Display screenSize = getWindowManager().getDefaultDisplay(); int screenWidth = screenSize.getWidth(); int screenHeight = screenSize.getHeight(); int iconWidth = screenWidth/4; int iconHeight= screenHeight/2; GridView gridview = (GridView) findViewById(R.id.gridview); gridview.setAdapter(new ImageAdapter(this, iconWidth, iconHeight)); } </code></pre> <p><strong>ImageAdapter.java</strong></p> <pre><code>public View getView(final int position, View convertView, ViewGroup parent) { ImageView imageView; if (convertView == null) { imageView = new ImageView(m_Context); imageView.setLayoutParams(new GridView.LayoutParams(m_width, m_height)); imageView.setScaleType(ImageView.ScaleType.FIT_CENTER); imageView.setPadding(8, 8, 8, 8); } else { imageView = (ImageView) convertView; } imageView.setImageResource(mThumbIds[position]); return imageView; } </code></pre> <p><strong>GridViewLayout.xml</strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;GridView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/gridview" android:layout_width="fill_parent" android:layout_height="fill_parent" android:verticalSpacing="10dp" android:horizontalSpacing="10dp" android:columnWidth="90dp" android:stretchMode="columnWidth" android:gravity="center" android:numColumns="2" android:background="#FFFFFF"/&gt; </code></pre> <p><strong>The result of the code looks like this:</strong></p> <p><img src="https://i.stack.imgur.com/hrve7.jpg" alt="wrong result"></p> <p><strong>This is what i would like it to look like:</strong></p> <p><img src="https://i.stack.imgur.com/5fsWA.jpg" alt="desired result"></p> <p>Note that the last screen shot is hard coded which is obviously not my wish. I want this to work in every screen size without hard coding. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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