简体   繁体   English

屏幕底部截断了Android文本

[英]Android text cut off in bottom of screen

Ok, after trying any solution I found I decided to put my code in here for help. 好的,尝试任何解决方案后,我发现我决定将代码放入这里寻求帮助。 I get HTML from JSON and I place it in a TextView to show it. 我从JSON获取HTML,并将其放在TextView中显示。

This is it: 就是这个:

hoursTextView.setText(Html.fromHtml(hours));
                                hoursTextView.setVisibility(View.VISIBLE);

My problem is, that whenever the content above this TextView takes alot of height, I see only cutted top letters of this TextView and I can't scroll down! 我的问题是,每当该TextView上方的内容占据很多高度时,我只会看到该TextView的前几个字母切掉而不能向下滚动!

This is my Layout XML: 这是我的布局XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent"
    >

    <ProgressBar
        android:id="@+id/loadData"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="50dp"
        android:layout_centerInParent="true"
        />

    <ImageView
        android:id="@+id/coverImg"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#000000"
        android:scaleType="fitCenter"
        android:adjustViewBounds="true"
        android:layout_marginBottom="5dp"
        />

    <TextView
        android:id="@+id/fbAbout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/coverImg"
        android:gravity="center"
        />

    <View
        android:id="@+id/seperator"
        android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:background="#eeeeee"
        android:layout_below="@+id/fbAbout"
        android:layout_marginBottom="5dp"
        android:layout_marginTop="5dp"
        />

    <LinearLayout
        android:id="@+id/buttons"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/seperator"
        android:layout_marginStart="5dp"
        android:layout_marginEnd="5dp"
        >

    <TextView
        android:id="@+id/type"
        android:layout_width="0dp"
        android:layout_height="70dp"
        android:background="@drawable/circle_text"
        android:textAlignment="center"
        android:gravity="center"
        android:padding="10dp"
        android:drawableTop="@drawable/beer"
        android:drawablePadding="5dp"
        android:text="TYPE"
        android:layout_weight="1"
        />

    <TextView
    android:id="@+id/age"
    android:layout_width="0dp"
        android:layout_height="70dp"
    android:background="@drawable/circle_text"
    android:textAlignment="center"
    android:gravity="center"
    android:padding="10dp"
    android:drawableTop="@drawable/age_big"
    android:drawablePadding="5dp"
        android:layout_marginStart="10dp"
        android:text="AGE"
        android:layout_weight="1"
    />

    <Button
        android:id="@+id/callToPlace"
        android:layout_width="0dp"
        android:layout_height="70dp"
        android:background="@drawable/circle_text"
        android:textAlignment="center"
        android:gravity="center"
        android:padding="10dp"
        android:drawableTop="@drawable/ic_call_black_24dp"
        android:drawablePadding="5dp"
        android:layout_marginStart="10dp"
        android:text="CALL"
        android:layout_weight="1"
        />

    <Button
        android:id="@+id/nav"
        android:layout_width="0dp"
        android:layout_height="70dp"
        android:background="@drawable/circle_text"
        android:textAlignment="center"
        android:gravity="center"
        android:padding="10dp"
        android:drawableTop="@drawable/navigate"
        android:drawablePadding="5dp"
        android:layout_marginStart="10dp"
        android:text="navigate"
        android:layout_weight="1"
        />

    </LinearLayout>


    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="HOURS"
        android:id="@+id/hoursTitle"
        android:layout_below="@+id/buttons"
        android:layout_centerHorizontal="true"
        android:visibility="gone"
        android:layout_marginTop="10dp"
        />
<!--This is the TextView which is cut -->
    <TextView
        android:id="@+id/hours"
        android:layout_marginTop="5dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/hoursTitle"
        android:visibility="gone"
        android:layout_centerHorizontal="true"
        android:gravity="center"
        />

</RelativeLayout>

The last TextView, with the ID of hours, is being cut on the bottom of the screen. 最后一个具有小时数ID的TextView在屏幕底部被剪切。 Hope someone can help me with this, thanks! 希望有人可以帮助我,谢谢!

Add the scroll view 添加滚动视图

<ScrollView
                android:layout_width="match_parent"
                android:layout_height="150dp" >
    <!--Just assume it whatever your height is-->
            <TextView
                android:id="@+id/hours"
                android:layout_marginTop="5dp"
                android:layout_width="wrap_content"
                android:layout_height="150dp"
                android:layout_below="@+id/hoursTitle"
                android:visibility="gone"
                android:layout_centerHorizontal="true"
                android:gravity="center"
                />
             </ScrollView>

You can use ScrollView for full screen. 您可以使用ScrollView进行全屏显示。

<ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent" 
        android:layout_below="@+id/output">
   <ProgressBar
        android:id="@+id/loadData"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="50dp"
        android:layout_centerInParent="true"
        />

    <ImageView
        android:id="@+id/coverImg"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#000000"
        android:scaleType="fitCenter"
        android:adjustViewBounds="true"
        android:layout_marginBottom="5dp"
        />

    <TextView
        android:id="@+id/fbAbout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/coverImg"
        android:gravity="center"
        />

    <View
        android:id="@+id/seperator"
        android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:background="#eeeeee"
        android:layout_below="@+id/fbAbout"
        android:layout_marginBottom="5dp"
        android:layout_marginTop="5dp"
        />

    <LinearLayout
        android:id="@+id/buttons"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/seperator"
        android:layout_marginStart="5dp"
        android:layout_marginEnd="5dp"
        >

    <TextView
        android:id="@+id/type"
        android:layout_width="0dp"
        android:layout_height="70dp"
        android:background="@drawable/circle_text"
        android:textAlignment="center"
        android:gravity="center"
        android:padding="10dp"
        android:drawableTop="@drawable/beer"
        android:drawablePadding="5dp"
        android:text="TYPE"
        android:layout_weight="1"
        />

    <TextView
    android:id="@+id/age"
    android:layout_width="0dp"
        android:layout_height="70dp"
    android:background="@drawable/circle_text"
    android:textAlignment="center"
    android:gravity="center"
    android:padding="10dp"
    android:drawableTop="@drawable/age_big"
    android:drawablePadding="5dp"
        android:layout_marginStart="10dp"
        android:text="AGE"
        android:layout_weight="1"
    />

    <Button
        android:id="@+id/callToPlace"
        android:layout_width="0dp"
        android:layout_height="70dp"
        android:background="@drawable/circle_text"
        android:textAlignment="center"
        android:gravity="center"
        android:padding="10dp"
        android:drawableTop="@drawable/ic_call_black_24dp"
        android:drawablePadding="5dp"
        android:layout_marginStart="10dp"
        android:text="CALL"
        android:layout_weight="1"
        />

    <Button
        android:id="@+id/nav"
        android:layout_width="0dp"
        android:layout_height="70dp"
        android:background="@drawable/circle_text"
        android:textAlignment="center"
        android:gravity="center"
        android:padding="10dp"
        android:drawableTop="@drawable/navigate"
        android:drawablePadding="5dp"
        android:layout_marginStart="10dp"
        android:text="navigate"
        android:layout_weight="1"
        />

    </LinearLayout>


    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="HOURS"
        android:id="@+id/hoursTitle"
        android:layout_below="@+id/buttons"
        android:layout_centerHorizontal="true"
        android:visibility="gone"
        android:layout_marginTop="10dp"
        />
<!--This is the TextView which is cut -->
    <TextView
        android:id="@+id/hours"
        android:layout_marginTop="5dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/hoursTitle"
        android:visibility="gone"
        android:layout_centerHorizontal="true"
        android:gravity="center"
        />
     </ScrollView>

Another Example: 另一个例子:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <LinearLayout

        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <Button
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Button 1" />

        <Button
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Button 2" />

        <Button
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Button 3" />

        <Button
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Button 4" />

        <Button
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Button 5" />

        <ProgressBar
            android:id="@+id/progressBar1"
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <RadioButton
            android:id="@+id/radioButton2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="RadioButton 1" />

        <RadioButton
            android:id="@+id/radioButton1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="RadioButton 2" />

        <ToggleButton
            android:id="@+id/toggleButton1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="ToggleButton" />

        <Button
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Button 6" />

        <SeekBar
            android:id="@+id/seekBar1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <Button
            android:id="@+id/button3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Button 7" />

        <Button
            android:id="@+id/button4"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Button 8" />

        <CheckBox
            android:id="@+id/checkBox1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="CheckBox" />

        <Button
            android:id="@+id/button2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Button 9" />

        <Button
            android:id="@+id/button1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Button 10" />

        <Button
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Button 11" />
    </LinearLayout>

</ScrollView>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM