在Android的许多活动布局的一部分 [英] One part of layout in many activities in Android
问题描述
这是我的想法的概念。我有我的活动:
This is concept of my idea. I have my activity:
public class FirstActivity extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.first_activity);
Button next = (Button) findViewById(R.id.nextActivity);
next.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
startActivity(intent);
}
});
}
}
这是XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.example.actionbartest.ClassTabs
android:id="@+id/tab"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
/>
</LinearLayout>
这是ClassTabs类:
and this is ClassTabs class:
public class ClassTabs extends LinearLayout{
Button nextButton;
LinearLayout tabs;
private int count = 0;
public ClassTabs(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ClassTabs(Context context) {
super(context);
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
((Activity)getContext()).getLayoutInflater().inflate(R.layout.tabview, this);
setupViewItems();
}
private void setupViewItems() {
nextButton = (Button) findViewById(R.id.nextActivity);
tabs = (LinearLayout) findViewById(R.id.toptab);
}
public void addTab(Button child){
if(child!=null){
tabs.addView(child);
count++;
}
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
}
和TabView的:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<LinearLayout
android:id="@+id/toptab"
android:layout_width="match_parent"
android:layout_height="40dp"
android:orientation="horizontal"
android:background="@color/blue">
</LinearLayout>
<Button
android:id="@+id/nextActivity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Next" />
</LinearLayout>
我想要做这样的事情:你在第一个活动。只有你所看到的是蓝色的40dp布局和下一步按钮。您按一下按钮,你会看到第二个活动,你看到蓝色的布局和按键相同的布局,但在蓝色的布局是在左边的一个按钮。当您再次单击下一步按钮,你会看到相同的布局,但在蓝色布局第三个活动是两个按钮,一个挨着一个,等我该怎么办,我在每一个活动相同的布局,但第二个活动应该知道,按钮,在第一活动中的溶液,而第三活动应该知道,并显示两个按钮等?
I want to do something like that: you are in first activity. Only what you see is blue 40dp layout and button "next". You click on the button and you see second activity and you see the same layout with blue layout and button, but in the blue layout is one button on left side. When you click again button "next" and you will see third activity with the same layout but in blue layout is two buttons, one next to one, etc. How can I do that I have the same layout in every activity, but second activity should know that button was added in the first activity, and the third activity should know and show two buttons etc?
推荐答案
把所有按钮的布局,但设置他们的知名度了,
然后
Put all button to your layout, but set their visibility gone, then
活动一:设置Button1的知名度可见
activity 1 : set button1 visibility to visible
活动2:设定按钮2能见度可见
activity 2 : set button2 visibility to visible
活动2:设定按钮2和按钮1能见度可见
activity 2 : set button2 and button 1 visibility to visible
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
通过捕捉大小就可以,如果使用条件来决定哪个按钮,将显示
by catching size you can use if condition to decide which button will be displayed
这篇关于在Android的许多活动布局的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!