线性布局没有正确间距

时间:2012-10-13 15:54:37

标签: android xml layout

嘿我在android xml中遇到这些线性布局的问题。最初我是在相对布局中做到的,它工作正常,但经过一些研究后我发现滚动视图内部的相对布局无法正常工作。所以现在经过大量的调整后,我的imageview显示出来,但是在它上面和下面有一个很大的余量,而我的textview甚至不会出现在它应该在图形编辑器中的位置,而是空白。

所以什么错了?我应该使用线性布局吗?

这大致看起来像http://www.mediafire.com/view/?z945tz2vrb2x46t

这是Abdul和Ralgha帮助之后的样子,以及设置基线性布局的高度来包装内容http://www.mediafire.com/view/?px17q2z3yyeo8az

由于

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:id="@+id/LinearLayout1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        >
        <TextView 
            android:id="@+id/today"
            android:src="@string/today"
            android:textSize="30dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:layout_width="fill_parent"
            />
        <ImageView
            android:id="@+id/image1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:src="@drawable/weeklylist_blocks"
            />

     </LinearLayout>
</ScrollView>

</LinearLayout>


`![screwed up layout][1]

3 个答案:

答案 0 :(得分:1)

android:layout_weight="1"

可能是您遇到问题的原因

答案 1 :(得分:1)

现在不要担心体重,请将其移除。在TextView中,将“android:src”更改为“android:text”(自然没有引号)。如果单独解决它,请删除textSize行,看看会发生什么。如果可以,那么您可以开始玩尺寸(如果需要还可以加权)。

此外,textSize应该以sp而不是dp给出。 sp代表文本,dp代表其他所有内容,但这并不是导致问题的原因。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:id="@+id/LinearLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        >
        <TextView 
            android:id="@+id/today"
            android:textSize="30sp"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:text="@string/today"
            />
        <ImageView
            android:id="@+id/image1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:src="@drawable/weeklylist_blocks"
            />

    </LinearLayout>
</ScrollView>

答案 2 :(得分:0)

它的作品就像魅力一样,使用以下编码来实现你的目标:

<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:gravity="center_vertical"
android:orientation="vertical" >

<ScrollView
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:fillViewport="true" >

<LinearLayout
    android:id="@+id/LinearLayout1"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="center_horizontal"
    android:orientation="vertical" >

    <TextView 
        android:id="@+id/today"
        android:src="@string/today"
        android:textSize="30sp"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:text="@string/today"
        />

    <ImageView
        android:id="@+id/image1"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:contentDescription="@string/nissan"
        android:src="@drawable/weeklylist_blocks" />

 </LinearLayout>
</ScrollView>

</LinearLayout>