Android textview 被裁剪
Android textview being cropped
我正在制作一个textView
动画,就像电影后的演员表(滑入屏幕和滑出屏幕),但是,textView
无法显示我所有的文字,即使我使用 wrap_content
.
布局xml:
<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"
android:background="#f2f1ef"
android:clipChildren="false"
android:paddingBottom="150dp"
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:paddingTop="150dp" >
<TextView
android:id="@+id/story_txt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing"
android:textSize="60sp" />
</LinearLayout>
向上滑动动画,slideup_in.xml:
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator"
android:fromYDelta="125%"
android:toYDelta="-150%"
android:duration="20000" />
Activity:
public class StoryActivity extends Activity {
TextView story_txt;
Animation animationSlideDownIn;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_story);
story_txt = (TextView) findViewById(R.id.story_txt);
Typeface face = Typeface
.createFromAsset(getAssets(), "font/secret.ttf");
story_txt.setTypeface(face);
animationSlideDownIn = AnimationUtils.loadAnimation(this,
R.anim.slideup_in);
animationSlideDownIn.setAnimationListener(animationSlideInListener);
story_txt.startAnimation(animationSlideDownIn);
}
AnimationListener animationSlideInListener = new AnimationListener() {
@Override
public void onAnimationEnd(Animation arg0) {
story_txt.setVisibility(View.INVISIBLE);
finish();
}
};
}
android:toYDelta="-150%"
此代码将允许您 运行 文本视图在原始位置之上。如果你想让它回到原来的位置,请使用
android:toYDelta="100%"
你有这个问题是因为 android:paddingBottom="150dp"
和 android:paddingTop="150dp"
删除这些,问题应该消失了。
您的布局 XML 应如下所示:
<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"
android:background="#f2f1ef"
android:clipChildren="false"
android:paddingLeft="30dp"
android:paddingRight="30dp">
<TextView
android:id="@+id/story_txt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing"
android:textSize="60sp" />
</LinearLayout>
如果确实需要顶部和底部的内边距,则应使用较小的值,例如 15dp。 150dp 太多了,导致文本无法填充可用 space.
这里的问题是您的 TextView
的最大高度值将等于您的屏幕高度(不考虑填充)。发生这种情况是因为您有一个 LinearLayout
作为您的布局父级 View
。您的 TextView
内容需要超过您的屏幕高度,以便您可以完整地看到它。
如果您将其更改为 ScrollView
,您的所有内容将完全可见,因为 ScrollView
显然在内容高度方面没有限制。
我正在制作一个textView
动画,就像电影后的演员表(滑入屏幕和滑出屏幕),但是,textView
无法显示我所有的文字,即使我使用 wrap_content
.
布局xml:
<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"
android:background="#f2f1ef"
android:clipChildren="false"
android:paddingBottom="150dp"
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:paddingTop="150dp" >
<TextView
android:id="@+id/story_txt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing"
android:textSize="60sp" />
</LinearLayout>
向上滑动动画,slideup_in.xml:
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator"
android:fromYDelta="125%"
android:toYDelta="-150%"
android:duration="20000" />
Activity:
public class StoryActivity extends Activity {
TextView story_txt;
Animation animationSlideDownIn;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_story);
story_txt = (TextView) findViewById(R.id.story_txt);
Typeface face = Typeface
.createFromAsset(getAssets(), "font/secret.ttf");
story_txt.setTypeface(face);
animationSlideDownIn = AnimationUtils.loadAnimation(this,
R.anim.slideup_in);
animationSlideDownIn.setAnimationListener(animationSlideInListener);
story_txt.startAnimation(animationSlideDownIn);
}
AnimationListener animationSlideInListener = new AnimationListener() {
@Override
public void onAnimationEnd(Animation arg0) {
story_txt.setVisibility(View.INVISIBLE);
finish();
}
};
}
android:toYDelta="-150%"
此代码将允许您 运行 文本视图在原始位置之上。如果你想让它回到原来的位置,请使用
android:toYDelta="100%"
你有这个问题是因为 android:paddingBottom="150dp"
和 android:paddingTop="150dp"
删除这些,问题应该消失了。
您的布局 XML 应如下所示:
<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"
android:background="#f2f1ef"
android:clipChildren="false"
android:paddingLeft="30dp"
android:paddingRight="30dp">
<TextView
android:id="@+id/story_txt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing"
android:textSize="60sp" />
</LinearLayout>
如果确实需要顶部和底部的内边距,则应使用较小的值,例如 15dp。 150dp 太多了,导致文本无法填充可用 space.
这里的问题是您的 TextView
的最大高度值将等于您的屏幕高度(不考虑填充)。发生这种情况是因为您有一个 LinearLayout
作为您的布局父级 View
。您的 TextView
内容需要超过您的屏幕高度,以便您可以完整地看到它。
如果您将其更改为 ScrollView
,您的所有内容将完全可见,因为 ScrollView
显然在内容高度方面没有限制。