这是一个简单的应用程序的初始显示一些TextViews和按钮的开始。无法从我的活动访问主窗口/布局
我想避免使用布局管理器,通过获取主窗口/布局的维度并使用它来以任何我想要的方式对组件进行硬编码。 但我的主要活动无法获得有关主窗口/布局的非零数据。 我不知道这是否应该是这种方式,或者如果我正在做一些愚蠢的事情,并希望得到一些帮助。
这是一个使用win10下的Ant并输出到USB'd电话的命令行项目。
我已经使用Android Tools 24.4.1更新了SDK Manager到Android 6.0(API 23)并安装了Android Support Lib的v23.2,尽管Ant在我以前的消息中可以看到不同的想法,有蚂蚁输出:
-build-setup:
[getbuildtools] Using latest Build Tools: 21.1.2.
我不知道这是否有所作为,但不是在这种情况下,我认为。
接下来的两个文件就完成了。
我会包括更多,但网站破坏我的代码的方式不鼓励上传到它。 (A)在我的第一篇文章之前我甚至没有看到它,(B)我现在不明白它。如果我能理解“如何格式化”,可能会有所帮助。 有太多的指令和太多的行话;例如什么是反拨?
不能有一个简单的格式,将采取一切你扔在它吗?
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"
...
总共有4个组件,每个角落一个,具有相同的layout_width和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);
...
屏幕结果:
它显示显示最后一个组件 - 全尺寸 - 与它的文本。
logcat results:
===============
D:\Android\ChessClock>adb shell
[email protected]:/ $ logcat clox:D *:S
--------- beginning of /dev/log/main
--------- beginning of /dev/log/system
D/clox (27214): [email protected]
D/clox (27214): main W/H=0/0
**