你好我是Android应用程序的新手,所以我想你的帮助。更改textview文字和位置,当你点击,然后再次点击回到原来的
所以基本上我所试图做的是改变的TextView从“更多”的内容,以“读少”,然后当我再次点击改回为“阅读更多”。然后我的第二个问题是,当我单击“阅读更多”时,如何从我的主要活动(java不是xml)更改我的textview位置,以及何时再次单击以再次返回到原始位置。
这是我的主要活动:
TextView paragraphmore;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
paragraphmore = (TextView) findViewById(R.id.paragraphmore);
// hide until its title is clicked
paragraphmore.setVisibility(View.GONE);
}
public void toggle_contents(View v){
paragraphmore.setVisibility(paragraphmore.isShown()
? View.GONE
: View.VISIBLE);
TextView view = (TextView) findViewById(R.id.readbutton);
view.setText("Read less");
}
这些都是textviews:
<TextView
android:id="@+id/readbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/readbutton"
android:clickable="true"
android:onClick="toggle_contents"
android:layout_marginTop="15dp"
android:textColor="#FFFFFF"
android:textSize="11sp">
</TextView>
<!--content to hide/show -->
<TextView android:id="@+id/paragraphmore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/paragraphmore"
android:layout_marginTop="15dp"
android:textColor="#FFFFFF"
android:textSize="11sp">
</TextView>
这工作!你有没有关于其他部分的想法? (定位) – pap