Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I had almost the same situation as you, and finally gave up on trying to use the xml layout from a resource file. No telling how many hours I spent fiddling with the xml, trying to get the percentages to line up correctly, with some success but not what I really wanted.</p> <p>So I finally decided to just create the layout on my own, programatically, inside the main activity, and it turned out pretty well...</p> <p>My layout is 3 parts. I have a company logo/image at the top, which I want to take up 20% of the screen.</p> <p>In the middle section, I have a scrollarea with filenames inside it. The file list is scrollable both up and down, and left to right. I want this area to be 75% of the screen.</p> <p>The 3rd section is just a single submit button which makes an asynchronous call to refresh the file list in the middle section, and it should be 5% of the screen.</p> <p>So, here's the code...</p> <pre><code>public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Resources res = this.getResources(); // Load the resources // Get available screen size Display display = getWindowManager().getDefaultDisplay(); int screenWidth = display.getWidth(); int screenHeight = display.getHeight(); LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.VERTICAL); layout.setId(topLayout); layout.setBackgroundColor(0xff000000); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT); layout.setLayoutParams(lp); double logoHeight = screenHeight * .20; logoHeight = Math.round(logoHeight); Bitmap logoImg = BitmapFactory.decodeResource(res, R.drawable.standardlogo); logoImg = Bitmap.createScaledBitmap(logoImg, screenWidth, (int)logoHeight, true); ImageView imageView = new ImageView(this); imageView.setImageBitmap(logoImg); imageView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); layout.addView(imageView); double bottomHeight = screenHeight * .05; bottomHeight = Math.round(bottomHeight); int scrollAreaHeight = screenHeight - (int)logoHeight - (int)bottomHeight - topHeight; ScrollView scroll = new ScrollView(this); scroll.setBackgroundColor(0xffd8d8d8); LinearLayout.LayoutParams slp = new LinearLayout.LayoutParams(screenWidth, scrollAreaHeight); scroll.setLayoutParams(slp); layout.addView(scroll); HorizontalScrollView hScroll = new HorizontalScrollView(this); hScroll.setBackgroundColor(0xffd8d8d8); LinearLayout.LayoutParams hlp = new LinearLayout.LayoutParams (LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); hScroll.setLayoutParams(hlp); scroll.addView(hScroll); TextView tv = new TextView(this); tv.setId(textArea); LayoutParams lparams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); tv.setLayoutParams(lparams); tv.setTypeface(Typeface.MONOSPACE); tv.setText(""); hScroll.addView(tv); Button btn = new Button(this); btn.setId(sendButton); btn.setOnClickListener(sendBtnListener); ViewGroup.LayoutParams blp = new ViewGroup.LayoutParams(screenWidth, LayoutParams.WRAP_CONTENT); btn.setLayoutParams(blp); btn.setText("List Import Directory"); layout.addView(btn); setContentView(layout); } </code></pre> <p>It's quite a bit of code, but it does exactly what I want it to do, and it works on all screen sizes I've tested it on. I have just a single company logo png image for the app, which is a large image that's meant for a 10" tablet.</p> <p>Note: The value of topHeight is hardcoded at 100, which works for all the devices I've tested it on. It's the height of the action or status bars at the top of the screen, and varies between devices, so I set it to 100 to handle up to two 48 pixel bars.. It leaves some unused space at the screen bottom if there's only one bar, but it's minimal.</p>
    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. VO
      singulars
      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