应用填充或layout_margin时ScrollView出现问题

时间:2014-01-21 20:39:19

标签: android android-layout padding android-scrollview

在我的xml布局文件中,我有一个ScrollView。在我使用权重在每个TableRow中分离TextViews之前,但这不能满足我的需求,所以我决定在TableLayout中使用列。

我的问题在于当我尝试将填充应用于ScrollView或“Container”RelativeLayout时,某些文本会被切断。如果我应用于ScrollView的任何子项,它不会显示TableLayout的最底层。我得到的最接近的是当我将填充应用于TableLayout中的TableRows时,但“Build Version”文本被水平截断(见下面的截图)。除此之外,它会令人满意。

layout.xml

<RelativeLayout 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/svMain"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/adMainBanner"
    android:layout_alignParentTop="true"
    android:fillViewport="true" >

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <!-- Build -->

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="15dp"
            android:gravity="center_horizontal"
            android:text="@string/build"
            android:textSize="18sp"
            android:textStyle="bold" />

        <TableRow android:layout_width="match_parent" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="0"
                android:text="@string/manufacturer" />

            <TextView
                android:id="@+id/tvManufacturer"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="1"
                android:text="text" />
        </TableRow>

        <TableRow android:layout_width="match_parent" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="0"
                android:text="@string/model" />

            <TextView
                android:id="@+id/tvModel"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="1"
                android:text="text" />
        </TableRow>

        <TableRow android:layout_width="match_parent" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="0"
                android:text="@string/hardware" />

            <TextView
                android:id="@+id/tvHardware"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="1"
                android:text="text" />
        </TableRow>

        <TableRow android:layout_width="match_parent" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="0"
                android:text="@string/board" />

            <TextView
                android:id="@+id/tvBoard"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="1"
                android:text="text" />
        </TableRow>

        <TableRow android:layout_width="match_parent" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="0"
                android:text="@string/bootloader" />

            <TextView
                android:id="@+id/tvBootLoader"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="1"
                android:text="text" />
        </TableRow>

        <TableRow android:layout_width="match_parent" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="0"
                android:text="@string/device" />

            <TextView
                android:id="@+id/tvDevice"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="1"
                android:text="text" />
        </TableRow>

        <TableRow android:layout_width="match_parent" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="0"
                android:text="@string/brand" />

            <TextView
                android:id="@+id/tvBrand"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="1"
                android:text="text" />
        </TableRow>

        <TableRow android:layout_width="match_parent" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="0"
                android:text="@string/android_version" />

            <TextView
                android:id="@+id/tvAndroidVersion"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="1"
                android:text="text" />
        </TableRow>

        <TableRow android:layout_width="match_parent" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="0"
                android:text="@string/build_version" />

            <TextView
                android:id="@+id/tvBuildVersion"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="1"
                android:text="text" />
        </TableRow>

        <!-- Service / Carrier -->

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="15dp"
            android:layout_marginTop="15dp"
            android:gravity="center_horizontal"
            android:text="@string/carrier_service"
            android:textSize="18sp"
            android:textStyle="bold" />

        <TableRow android:layout_width="match_parent" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="0"
                android:text="@string/carrier" />

            <TextView
                android:id="@+id/tvCarrier"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="1"
                android:text="text" />
        </TableRow>

        <TableRow android:layout_width="match_parent" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="0"
                android:text="@string/phone_number" />

            <TextView
                android:id="@+id/tvPhoneNumber"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="1"
                android:text="text" />
        </TableRow>

        <TableRow android:layout_width="match_parent" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="0"
                android:text="@string/service_mode" />

            <TextView
                android:id="@+id/tvServiceMode"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="1"
                android:text="text" />
        </TableRow>

        <!-- Network -->

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="15dp"
            android:layout_marginTop="15dp"
            android:gravity="center_horizontal"
            android:text="@string/network"
            android:textSize="18sp"
            android:textStyle="bold" />

        <TableRow android:layout_width="match_parent" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="0"
                android:text="@string/phone_type" />

            <TextView
                android:id="@+id/tvPhoneType"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="1"
                android:text="text" />
        </TableRow>

        <TableRow android:layout_width="match_parent" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="0"
                android:text="@string/network_type" />

            <TextView
                android:id="@+id/tvNetworkType"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="1"
                android:text="text" />
        </TableRow>

        <TableRow android:layout_width="match_parent" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="0"
                android:text="@string/baseband" />

            <TextView
                android:id="@+id/tvBaseBand"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_column="1"
                android:text="text" />
        </TableRow>

        <!-- CPU -->

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="15dp"
            android:layout_marginTop="15dp"
            android:gravity="center_horizontal"
            android:text="@string/cpu_info"
            android:textSize="18sp"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/tvCpuInfo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_column="0"
            android:text="text" />

        <!-- Ram -->
        <!-- If I apply padding/margin to any container layout,
             this gets cut off(does not show in scrollview)-->

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="15dp"
            android:layout_marginTop="15dp"
            android:gravity="center_horizontal"
            android:text="@string/ram_info"
            android:textSize="18sp"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/tvRamInfo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_column="0"
            android:text="text" />
    </TableLayout>
</ScrollView>

<com.google.ads.AdView
    xmlns:googleads="http://schemas.android.com/apk/lib/com.google.ads"
    android:id="@+id/adMainBanner"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    googleads:adSize="SMART_BANNER"
    googleads:adUnitId="@string/admob_banner_id"
    googleads:loadAdOnCreate="true" />

</RelativeLayout>

截图

如果没有任何填充或边距,它的外观如何,Build Version被截断: How It looks without any padding or margin, Build Version is cut off

这是整个构建版本: This is the whole Build Version

为什么Build Version文本不会换行到新行?在我实现了这一点之后,我应该如何在我的整个布局文件中应用填充/边距而不在ScrollView中添加一些东西?如有任何帮助,非常感谢:)

1 个答案:

答案 0 :(得分:1)

可能是因为它不包含任何空格。试试:

android:singleLine="false"

android:ems="30" // or whatever number of characters you want per line