我在Android TextView中有一个活动,再次跟随ListView TextView。第一个TextView的内容填充整个屏幕,以便查看用户必须滚动的ListView和第二个TextView。现在我希望在活动开始时显示第二个TextView而不是第一个TextView。
相反,我希望TextView2在活动开始时可见。
EDITED
根据@Urban建议的示例代码
public class FocusTestActivity extends Activity {
private static final String TAG = "FocusTestActivity";
ScrollView scroll;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView text1 = (TextView) findViewById(R.id.text1);
TextView text2 = (TextView) findViewById(R.id.text2);
TextView text3 = (TextView) findViewById(R.id.text3);
String hello = "We provide services to K-12 education sector."
+ "Our services include Feasibility report, Marketing, Curriculum design"
+ "Teachers planning, Design and Technology, Parents expectation"
+ "management, Transport planning, Day-to-day operations and Statutory"
+ "compliances. Please find a brief introduction attached with mail. Also visit"
+ "www.wissenways.com We can help you with overall process of setting-up school. We have"
+ "experience include establishing International, pre-school and CBSE"
+ "schools from scratch. Please feel free to contact if you need some help in your school venture."
+ "Best of Luck!<br/><br/>";
text1.setText(Html.fromHtml(hello));
text2.setText(Html.fromHtml(hello));
text3.setText(Html.fromHtml(hello));
ScrollView scroll = (ScrollView) findViewById(R.id.scrollcontainer);
}
public void onStart() {
super.onStart();
Log.d(TAG,"Inside onStart");
scroll.post(new Runnable() {
@Override
public void run() {
scroll.fullScroll(ScrollView.FOCUS_DOWN);
}
});
}
}
XML代码
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollcontainer"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/text1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
android:textSize="17sp"/>
<TextView
android:id="@+id/text2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
android:textSize="17sp"/>
<TextView
android:id="@+id/text3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
android:textSize="17sp"/>
</LinearLayout>
</ScrollView>
LOGCAT输出:
答案 0 :(得分:2)
getScrollView().post(new Runnable() {
@Override
public void run() {
getScrollView().fullScroll(ScrollView.FOCUS_DOWN);
}
});
在onCreate中使用此代码应该在底部位置启动scrollview(列表和两个文本视图)。我不知道为什么你会这样做,我猜你可以有一个更好的方法来做你想要的而不是强迫滚动位置到底部,但无论如何...
This是从上面的代码中取出的问题,您可以搜索它。
希望这会有所帮助。
答案 1 :(得分:1)
以下是我可以给你的3个简单选项:
更改地点
使用第二个textview进行另一项活动并首先启动该活动,然后向您显示当前的活动
在活动开始时在第二个文本视图中显示带有文本的Toast(问题是用户关闭它并且您想再次显示它或者用户想再次看到它需要启动一个新的吐司)
我不完全理解你对这个问题的困难
编辑: 什么时候第一个textview必须显示在顶部?如果不是只做第一个选项:\如果在某些情况下,在顶部和底部有一个空的文本视图,并通过代码将其文本更改为您想要的那一刻
答案 2 :(得分:0)
您还可以在xml文件中使用RealtiveLayout
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<TextView
android:id="@+id/txtview2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ListView
android:id="@id/android:list"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_below="@id/textview2/>
<TextView
android:id="@+id/txtview1"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_below="@id/android:list"/>
</RelativeLayout>