0

This is the start of a simple app to initially display some TextViews and Buttons.

I want to avoid using layout managers by getting the dimensions of the main window/layout and using that to hard-code the components any way I want. But my main Activity can't get non-zero data about the main window/layout. I don't know if it's supposed to be this way or if I'm doing something dumb, and would appreciate some help.

This is a command line project using Ant under win10 and outputting to a USB'd phone.

I've updated the SDK Manager to Android 6.0 (API 23) with Android Tools 24.4.1 and installed v23.2 of the Android Support Lib, although Ant seems to think differently as you can see in my previous message which has the Ant output:

-build-setup:
[getbuildtools] Using latest Build Tools: 21.1.2.

I don't know if that makes a difference, but not in this case I think.

The next two files are complete as far as they go.

I would have included more but the way the website mangles my code doesn't encourage uploading to it.

It might have helped if I could have comprehended the 'How to Format' but (A) I didn't even see it before my first post and (B) I don't understand it now. There are far too many instructions and too much jargon; e.g. what is a backtick?

Can't there be a simple format that will take everything you throw at it?

main.xml
========
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    package="com.Chatterton.Peter.ChessClock"
    android:id="@+id/main_window"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:id="@+id/time_text_view_left"
        android:text="top_left"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />
    <Button
        android:layout_alignParentBottom="true"
...

There are a total of 4 components, one per corner, with the same layout_width and height.

ChessClockActivity.java
=======================
package com.Chatterton.Peter.ChessClock;
import android.app.Activity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.content.Intent;
import android.app.Activity;
import android.os.Bundle;
import android.graphics.Color;
import android.widget.TextView;
import android.util.Log;

public class ChessClockActivity extends Activity
    {
    public int winOriginX=10, winOriginY=20, winWidth=44, winHeight=66;

    @Override
    public void onCreate( Bundle savedInstanceState )
        {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        RelativeLayout mainLayout = (RelativeLayout)findViewById( R.id.main_window );
        int mainWidth = mainLayout.getWidth();
        int mainHeight = mainLayout.getHeight();
        Log.d( "clox", "mainLayout=" + mainLayout );
        Log.d( "clox", "main W/H=" + mainWidth + "/" + mainWidth );           
...

Screen Results:

It shows the last component displayed -- full-size -- with its text.

logcat results:
===============
D:\Android\ChessClock>adb shell  
shell@android:/ $ logcat clox:D *:S   
--------- beginning of /dev/log/main  
--------- beginning of /dev/log/system  
D/clox    (27214): mainLayout=android.widget.RelativeLayout@41755b80    
D/clox    (27214): main W/H=0/0
**
Chad Nouis
  • 6,861
  • 1
  • 27
  • 28
chatt
  • 45
  • 7

1 Answers1

0

They have no size at this point of the initialization process.

Click here to an answer that will let you access the sizes of your components after they have been displayed.

Or perhaps you can get the window size and figure the placement of your components by that value...... Answer here

Community
  • 1
  • 1
RorschachDev
  • 354
  • 4
  • 11