2017-09-11 9 views
0

現在、私はAndroidタブレット用のアプリケーションを開発しています。私は、画面を2つの部分に分割し、サブビューを可視にする方法またはアプローチを探します。この効果がどこで見つかったのか分かりません(iOSまたはAndroidアプリ)。Androidはアクティビティを2つの部分に分割します

説明のため

私は二つの絵が取り付けられてい:

enter image description here

ビューXをクリックした後サブビューは正確に以下に表示されます(画面の残りの部分が下方に移動されます):

enter image description here

この影響を知っている人はいますか? よろしくお願いいたします。

答えて

1

アンドロイドスタジオでは、断片をあなたの活動に展開できます。

は、ここに例を示します

Main2Activity.java

public class Main2Activity extends AppCompatActivity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main2); 

     final FrameLayout frameLayout = (FrameLayout) findViewById(R.id.frameLayout); 
     Button btn = (Button) findViewById(R.id.button3); 
     btn.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 
       PlusOneFragment myf = new PlusOneFragment(); 
       frameLayout.setVisibility(View.VISIBLE); 
       FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); 
       transaction.add(R.id.frameLayout, myf); 
       transaction.commit(); 

      } 
     }); 
    } 
} 

にactivity_main2.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.testing.testinglibraryapps.Main2Activity"> 

    <Button 
     android:id="@+id/button3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Button" 
     app:layout_constraintTop_toTopOf="parent" 
     android:layout_marginTop="8dp" 
     android:layout_marginLeft="8dp" 
     app:layout_constraintLeft_toLeftOf="parent" 
     android:layout_marginStart="8dp" /> 

    <Button 
     android:id="@+id/button4" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Button" 
     app:layout_constraintTop_toTopOf="parent" 
     android:layout_marginTop="8dp" 
     android:layout_marginRight="8dp" 
     app:layout_constraintRight_toRightOf="parent" 
     android:layout_marginEnd="8dp" /> 

    <FrameLayout 
     android:id="@+id/frameLayout" 
     android:layout_width="0dp" 
     android:layout_height="200dp" 
     android:layout_marginLeft="8dp" 
     android:layout_marginRight="8dp" 
     android:layout_marginTop="0dp" 
     android:visibility="gone" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/button3"> 

    </FrameLayout> 

    <Button 
     android:id="@+id/button5" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Button" 
     android:layout_marginLeft="8dp" 
     app:layout_constraintLeft_toLeftOf="parent" 
     android:layout_marginTop="0dp" 
     app:layout_constraintTop_toBottomOf="@+id/frameLayout" /> 

    <Button 
     android:id="@+id/button6" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Button" 
     android:layout_marginRight="8dp" 
     app:layout_constraintRight_toRightOf="parent" 
     android:layout_marginTop="0dp" 
     app:layout_constraintTop_toBottomOf="@+id/frameLayout" /> 
</android.support.constraint.ConstraintLayout> 

で見て、私は下のビューを置くことでframeLayout可視性のトリックを置きます彼らは落ちる。私の例では

とPlusOneFragmentため、uがあなたが、これは多くの方法で達成することができ、独自のフラグメント

0

でそれを変更することができます。私が考えることができる最も簡単なのは、ビューを直接表示/非表示にすることです。

レイアウト:あなたがそうのようにしたい

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation=vertical> 


    <LinearLayout <!-- this is the top layout --> 
     android:id:@+id/myTopLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation=horizontal> 

     .... YOUR LAYOUT VIEWS .... 

    </LinearLayout> 

    <LinearLayout <!-- this is layout you will show/hide --> 
     android:id:@+id/myShowHideLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation=horizontal 
     android:visibility="gone"> 

     .... YOUR LAYOUT VIEWS .... 

    </LinearLayout> 

    <LinearLayout <!-- this is the bottom layout --> 
     android:id:@+id/myBottomLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation=horizontal> 

     .... YOUR LAYOUT VIEWS .... 

    </LinearLayout> 

</LinearLayout> 

今、あなたの活動にあなたを表示または非表示に真ん中レイアウト:

LinearLayout myShowHideLayout; 

... onCreate(...){ 

    myShowHideLayout = (LinearLayout)findViewById(R.id. myShowHideLayout); 
    myShowHideLayout.setVisibility(View.VISIBLE); 
} 
関連する問題