从活动中移除textview和按钮,并在单击按钮后向上拉动其余组件



我有一个从XML文件以线性布局加载的活动。我想要的是,当应用程序运行时,应该出现一个额外的文本视图和一个按钮。但当用户点击"bGotIt"按钮[使用sharedpreferences内容]时,它不应该再次出现

但我想要的是,文本视图和按钮必须出现在活动的顶部,并且必须按下我的永久组件!!当单击"bGotIt"按钮时,这些文本视图和按钮都应该消失,永久组件必须自行拉起并填充屏幕。

<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>
// 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);
            }
        });
    }
}

相关内容

  • 没有找到相关文章

最新更新