Android 从活动中删除textview和按钮,并在单击按钮后向上拉动其余组件
我有一个从XML文件以线性布局加载的活动。 我想要的是,当应用程序运行时,应该显示一个额外的文本视图和一个按钮。但当用户点击“bgott”按钮[使用SharedReferences工具]时,它不应该再出现 但是我想要的是文本视图和按钮必须出现在活动的顶部,并且必须按下我的永久组件!!当点击“bgott”按钮时,这些文本视图和按钮都应该消失,永久性组件必须向上拉并填满屏幕Android 从活动中删除textview和按钮,并在单击按钮后向上拉动其余组件,android,android-layout,user-interface,sharedpreferences,Android,Android Layout,User Interface,Sharedpreferences,我有一个从XML文件以线性布局加载的活动。 我想要的是,当应用程序运行时,应该显示一个额外的文本视图和一个按钮。但当用户点击“bgott”按钮[使用SharedReferences工具]时,它不应该再出现 但是我想要的是文本视图和按钮必须出现在活动的顶部,并且必须按下我的永久组件!!当点击“bgott”按钮时,这些文本视图和按钮都应该消失,永久性组件必须向上拉并填满屏幕 <LinearLayout xmlns:android="http://schemas.android.com/apk/
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="@+id/done"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/firstTimeText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Bla bla bla bla "
/>
<Button
android:id="@+id/bGotIt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Got it !! "
android:visibility="gone"
/>
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
Here I have my permanent components
</RelativeLayout>
</FrameLayout>
</LinearLayout>
这是我的永久部件
//试试这个方法,希望这能帮助你。。。
注意:我尝试将此“按钮”和“文本视图”放在一个布局中,并尝试在“bgott”“按钮”单击时更改布局可见性(显示/隐藏)。
**主要活动**
这是我的永久部件
**我的活动**
公共类MyActivity扩展了活动{
私人线路布局可修改;
专用按钮bgott;
@凌驾
创建时的公共void(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lnrHidable=(LinearLayout)findViewById(R.id.lnrHidable);
bgott=(按钮)findViewById(R.id.bgott);
//可作为您的共享参考访问
bGotIt.setVisibility(View.VISIBLE);
bgott=(按钮)findViewById(R.id.bgott);
bgott.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
lnrHidable.setVisibility(View.GONE);
}
});
}
}
它仍然不工作:\XML文件显示错误。。。。。。我可以在framelayout中的相对布局中拥有任意数量的组件。。。。。。。。正确的?
// try this way, hope this will help you...
Note : i try to put this "Button" and "TextView" in one layout and just try to change layout visibility (Show/Hide) on "bGotIt" "Button" click.
**activity_main**
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/lnrHidable"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:id="@+id/done"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/firstTimeText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Bla bla bla bla "/>
</LinearLayout>
<Button
android:id="@+id/bGotIt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Got it !! "
android:visibility="gone"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
Here I have my permanent components
</RelativeLayout>
</FrameLayout>
</LinearLayout>
**MyActivity**
public class MyActivity extends Activity{
private LinearLayout lnrHidable;
private Button bGotIt;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lnrHidable = (LinearLayout) findViewById(R.id.lnrHidable);
bGotIt = (Button) findViewById(R.id.bGotIt);
// visiable as your sharedpreferences
bGotIt.setVisibility(View.VISIBLE);
bGotIt = (Button) findViewById(R.id.bGotIt);
bGotIt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
lnrHidable.setVisibility(View.GONE);
}
});
}
}