0

我是 Android 应用程序开发的新手。

android:layout_someproperty我想知道指定和之间有什么区别android:someproperty。例如android:layout_heightandroid:height

My Eclipse on hover 提供以下信息

android:layout_height : Specifies the basic height of the view.[dimension.enum]
android:height : Makes the TextView exactly this many pixel tall[dimention]

但我不明白。我的代码类似于

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/mainscreen_background"
    android:layout_gravity="center"
    android:padding="30dip"
    android:orientation="vertical"
    tools:context=".TicTacToe" >

    <TextView 
        android:text="@string/game_title"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:layout_marginBottom="25dip"
        android:layout_gravity="center"
        android:textSize="24.5sp"/>
</LinearLayout> 

什么是有意义的,每个有什么影响?

  1. android:layout_heightLinerLayout标签中设置。
  2. android:layout_heightTextView标签中设置。
  3. android:heightLinerLayout标签中设置。
  4. android:heightTextView标签中设置。

据我的理解,LinearLayout将是TextView(如果我错了,请纠正我)的父母。

4

1 回答 1

0

好吧,设置 layout_height 其实并不是 View 的一个属性,而是它周围的 Layout。android:height,设置视图高度。

通常,您使用 layout_height 并尽量避免使用任何类型的绝对值,因为这在具有不同纵横比/大小的屏幕上看起来很奇怪

您必须在 textview 和 LinearLayout 上都设置 android:layout_height。

如果这是您的整个片段,我会将根视图在两个维度上都设置为 match_parent,通常您将子视图 layout_height 设置为包装内容,将 layout_width 设置为匹配父视图。

这将创建一个占据其父级整个宽度的文本视图,并适应其内容的大小。

于 2013-10-20T20:04:23.613 回答