0
主頁面在頂部有一個horizontalScrollView,在其中有一些TextView文本字段。我希望能夠滾動並單擊TextView文本上的任何內容,並且它會更改RelativeLayout以匹配在HorizontalScrollView中所做的選擇。Android滑動菜單更改頁面上的內容可以這樣做嗎?
main.xml中
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<HorizontalScrollView android:id="@+id/horizontalScrollView1" android:layout_height="wrap_content" android:scrollbars="none" android:layout_width="wrap_content">
<LinearLayout android:layout_width="match_parent" android:orientation="horizontal" android:layout_height="match_parent" android:id="@+id/linearLayout1">
<TextView android:layout_height="wrap_content" android:layout_weight="1" android:layout_width="70dp" android:id="@+id/EditTOne" android:text="tOne"></TextView>
<TextView android:layout_height="wrap_content" android:layout_weight="1" android:layout_width="70dp" android:id="@+id/EditTTwo" android:text="tTwo"></TextView>
<TextView android:layout_height="wrap_content" android:layout_weight="1" android:layout_width="70dp" android:id="@+id/EditTThree" android:text="tThree"></TextView>
<TextView android:layout_height="wrap_content" android:layout_weight="1" android:layout_width="70dp" android:id="@+id/EditTFour" android:text="tFour"></TextView>
<TextView android:layout_height="wrap_content" android:layout_weight="1" android:layout_width="70dp" android:id="@+id/EditTFive" android:text="tFive"></TextView>
<TextView android:layout_height="wrap_content" android:layout_weight="1" android:layout_width="70dp" android:id="@+id/EditTSix" android:text="tSix"></TextView>
<TextView android:layout_height="wrap_content" android:layout_weight="1" android:layout_width="70dp" android:id="@+id/EditTSeven" android:text="tSeven"></TextView>
</LinearLayout>
</HorizontalScrollView>
<RelativeLayout android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/relativeLayout1"></RelativeLayout>
</LinearLayout>
我叫音第二頁面佈局,其將被鏈接到HorizontalScrollView菜單選項基調。
tone.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="This is tOne"></TextView>
</LinearLayout>
主要活動將標誌,如果前4個選項之一是通過寫logcat的選擇。如果用戶點擊HorizontalScrollView中的tOne選項,是否可以在relativelayout中顯示tone.xml?那麼如果用戶在RelativeLayoutView等中選擇tTwo顯示ttwo.xml?
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.RelativeLayout;
import android.widget.TextView;
public class SlideMenu extends Activity implements OnClickListener {
/** Called when the activity is first created. */
TextView tOne, tTwo, tThree, tFour, tFive, tSix, tSeven, tEight, tNine, tTen;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
RelativeLayout vSpace = (RelativeLayout)findViewById(R.id.relativeLayout1);
tOne = (TextView)findViewById(R.id.EditTOne);
tTwo = (TextView)findViewById(R.id.EditTTwo);
tThree = (TextView)findViewById(R.id.EditTThree);
tFour = (TextView)findViewById(R.id.EditTFour);
tFive = (TextView)findViewById(R.id.EditTFive);
tSix = (TextView)findViewById(R.id.EditTSix);
tSeven = (TextView)findViewById(R.id.EditTSeven);
tOne.setOnClickListener(this);
tTwo.setOnClickListener(this);
tThree.setOnClickListener(this);
tFour.setOnClickListener(this);
tFive.setOnClickListener(this);
tSix.setOnClickListener(this);
tSeven.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()) {
//--------------
case R.id.EditTOne:
System.out.println("Text One pressed");
break;
case R.id.EditTTwo:
System.out.println("Text Two pressed");
break;
case R.id.EditTThree:
System.out.println("Text Three pressed");
break;
case R.id.EditTFour:
System.out.println("Text Four pressed");
break;
}
}
}
由於Craigy運作良好。我能否動畫從tOne到tTwo的過渡。例如,將一個佈局滑出並滑入下一個佈局? – John
@John請在新問題中提出。 –
老實說,我對動畫沒有太多的瞭解,但是我嘗試了這裏的例子(http://www.inter-fuser.com/2009/07/android-transtions-slide-in-and-slide。 HTML)取得了一些成功。我能夠讓它在兩個視圖之間切換視圖,但由於看起來只有'showNext'和'showPrevious',所以邏輯變得很難。也許你可以跟蹤自己在哪個視圖上,然後重複調用'showNext'。也許你應該發佈一個新問題。 – Craigy