鉴于在Android中相对布局不显示 [英] View not showing in a relative layout in Android

查看:140
本文介绍了鉴于在Android中相对布局不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我张贴了这个已经,但我得到了新的信息,可以帮助你帮我...
我有这样的布局有问题,我无法找出什么是错的。正如你所看到的,还有一个记时计和相对布局内的表,但天文台表不显示,甚至没有一个空格。

I posted this already but i got new information that may help you to help me... I have a problem with this layout and i cannot find out what is wrong. As you can see, there is a chronometer and a table inside a relative layout but the chronometer does not show, not even a blank space.

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/firstLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<Chronometer
    android:id="@+id/chrono"
    android:textColor="#4169E1"
    android:textSize="20sp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:text="Chronometer"
/>
<TableLayout 
    android:id="@+id/parentLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
</TableLayout>
</RelativeLayout>

所以,我试图改变天文钟和tablelayout的顺序。我也试过改变layout_width和layout_height属性,但我什么也没得到。所以我去了我的java类,我发现,这个问题可能会在这里:

So i tried changing the order of the chronometer and tablelayout. I tried also changing the layout_width and layout_height properties, but i got nothing. So i went to my java class and i found out that the issue might be here:

 private final void createGameBoard(short gridSize) {
  DisplayMetrics metrics = new DisplayMetrics();
  getWindowManager().getDefaultDisplay().getMetrics(metrics);

  TableLayout tableLayout;
  tableLayout = (TableLayout) findViewById(R.id.parentLayout);    
  tableLayout.removeAllViews();

  board = GameBoard.createGameBoard(this, 
        bitmap, 
        tableLayout,
        (int) (metrics.widthPixels * metrics.density),
        (int) ((metrics.heightPixels * metrics.density)-h1),
        gridSize);
}

其中GameBoard.createGameBoard是:

where GameBoard.createGameBoard is:

public static GameBoard createGameBoard(Context context, 
                             Bitmap bitmap, 
                             TableLayout parentLayout,
                             int width,
                             int height,
                             short gridSize) {

  board = new GameBoard(context, 
                   bitmap, 
                   parentLayout, 
                   width, 
                   height, 
                   gridSize);

  return board;
}

所以我想这显示天文台表的问题来自于创建游戏键盘,因为从目前的窗口,它是用来设置游戏键盘的高度,采取的指标。
有什么建议?

So i guess that the problem displaying the chronometer comes from the creation of the gameboard, because of the metrics taken from the current window, which is used to set the height of the gameboard. any suggestions?

推荐答案

您XML code:

<Chronometer
    android:id="@+id/chrono"
    android:textColor="#4169E1"
    android:textSize="20sp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:text="Chronometer"
/>
<TableLayout 
    android:id="@+id/parentLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
>

这将迫使TableLayout在全屏显示等,天文台被隐藏。

This will force TableLayout to be shown in full screen and so, Chronometer is being hidden.

试着改变像下列条件之一:

Try changing like one of followings:

1)

<Chronometer
    android:id="@+id/chrono"
    android:textColor="#4169E1"
    android:textSize="20sp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:text="Chronometer"
/>
<TableLayout 
    android:id="@+id/parentLayout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
>

这将换表的内容,所以天文台将获得空间。

Which will wrap content of table, so Chronometer will get space.

2)

<Chronometer
    android:id="@+id/chrono"
    android:textColor="#4169E1"
    android:textSize="20sp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:text="Chronometer"
/>
<TableLayout 
    android:id="@+id/parentLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@id/chrono"
>

这将迫使天文台采取如下表布局充分空间,见表格布局后。

This will force Chronometer to take full space below table layout after table layout is shown.

希望这有助于。

这篇关于鉴于在Android中相对布局不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆