android:layout_property和android:property之间的区别

时间:2013-10-20 19:59:15

标签: android android-layout android-view

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

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

我的Eclipse悬停时提供以下信息

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_height代码中设置LinerLayout
  2. android:layout_height代码中设置TextView
  3. android:height代码中设置LinerLayout
  4. android:height代码中设置TextView
  5. 据我所知,LinearLayout将成为TextView的父母(如果我错了,请纠正我)。

1 个答案:

答案 0 :(得分:0)

好吧,设置layout_height实际上不是View的属性,而是它的环绕布局。 android:height,设置Views height。

一般情况下,你使用layout_height并尝试避免任何类型的绝对值,因为在不同宽高比/大小的屏幕上看起来很奇怪

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

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

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

相关问题