TextView由于父项';android中的s LinearLayout wrap_内容

TextView由于父项';android中的s LinearLayout wrap_内容,android,xml,android-layout,android-linearlayout,Android,Xml,Android Layout,Android Linearlayout,我要做的是制作一个居中的框,其中包含一些文本简介和一个按钮来继续。我能够通过使用wrap_内容使方框居中,而不是占据整个屏幕,但是这些广告条有几行长,包含它们的文本视图并没有显示所有文本。以下是我所拥有的: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill

我要做的是制作一个居中的框,其中包含一些文本简介和一个按钮来继续。我能够通过使用wrap_内容使方框居中,而不是占据整个屏幕,但是这些广告条有几行长,包含它们的文本视图并没有显示所有文本。以下是我所拥有的:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center"
    android:background="@color/background"
    android:orientation="vertical" >


    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_gravity="center"
        android:background="@color/content"
        android:padding="10dp"
     >

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:gravity="center"
            android:text="@string/title"
            android:textColor="@color/black" />

       <TextView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="@string/teacher_head" 
            android:textColor="@color/black" />

        <TextView
            style="@style/home_blurb"
        android:text="@string/teacher_blurb" />

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="@string/student_head"
            android:textColor="@color/black"  />

        <TextView
        android:text="@string/student_blurb" 
            style="@style/home_blurb" />


        <Button
            android:layout_width="wrap_content"
        android:layout_height="0dip"
        android:layout_gravity="center"
        android:layout_weight="0.1"
        android:gravity="center"
            android:paddingTop="5dp"
            android:text="@string/go_to_app" />


</LinearLayout>
</LinearLayout>

家在哪里

<style name="home_blurb" parent="android:TextAppearance">
    <item name="android:paddingBottom">5dp</item>
    <item name="android:textColor">@color/black</item>
    <item name="android:layout_width">fill_parent</item>
    <item name="android:layout_height">fill_parent</item>
    <item name="android:layout_weight">1</item>
    <item name="android:textSize">12dp</item>     
</style>

5dp
@颜色/黑色
填补家长的空缺
填补家长的空缺
1.
12dp

内线布局将其自身设置为按钮的宽度,我可以接受,但是有没有办法使其足够宽以包含所有文本,而无需设置特定的像素测量值(如html/css中的屏幕百分比)

您可以在第二个
线性布局中使用

android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="20dp"
android:layout_marginTop="20dp"
这样,无论文本有多大,每次布局都会保持在中心位置,并在周围留出一些空间

如果需要,您可以为每个元素提供滚动条,您可以通过为每个元素添加特定的最大高度来执行此操作,然后您可以执行此操作


android:scrollbars=“vertical”
和在code
textview.setMovementMethod(新的ScrollingMovementMethod())中

您可以在第二个
线性布局中使用

android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="20dp"
android:layout_marginTop="20dp"
这样,无论文本有多大,每次布局都会保持在中心位置,并在周围留出一些空间

如果需要,您可以为每个元素提供滚动条,您可以通过为每个元素添加特定的最大高度来执行此操作,然后您可以执行此操作


android:scrollbars=“vertical”
和在code
textview.setMovementMethod(新的ScrollingMovementMethod())中

我也有同样的问题。碰巧我正在使用:

android:layout_gravity="center"
不要用那个。使用:

android:gravity="center"
相反。也许你应该在被切断的文本视图上使用android:gravity=“center”

一些帮助:

android:layout_gravity是视图的外部重力。这意味着,要指定视图应该接触其父对象边界的方向


安卓:重力是该视图的内部重力。这意味着,它的内容应该向哪个方向对齐。

我也有同样的问题。碰巧我正在使用:

android:layout_gravity="center"
不要用那个。使用:

android:gravity="center"
相反。也许你应该在被切断的文本视图上使用android:gravity=“center”

一些帮助:

android:layout_gravity是视图的外部重力。这意味着,要指定视图应该接触其父对象边界的方向


安卓:重力是该视图的内部重力。这意味着,它的内容应该在哪个方向对齐。

要使按钮变宽还是线性布局?顺便说一句,wtat将成为文本?它有多大?你想让按钮变宽还是线性排列?顺便说一句,wtat将成为文本?它会有多大?为相同值的边距添加4行代码不是好的做法。如果您只添加android:layout\u margin=“20dp”
会更好。这与上面4行代码的作用相同,但只有一行。是的,你是对的。我写了四行代码,考虑到他将为边距设置不同的值。为相同值的边距添加4行代码不是好的做法。如果您只添加android:layout\u margin=“20dp”
会更好。这与上面4行代码的作用相同,但只有一行。是的,你是对的。我写了四行,考虑到他将为保证金设定不同的值。