2017-09-11 15 views
0

현재 Android 태블릿 용 애플리케이션을 개발 중입니다. 나는 스크린을 두 조각으로 나누고 서브 뷰를 보이게하는 방법이나 접근법을 찾는다. 나는이 효과 (iOS 또는 Android 앱)를 어디에서 발견했는지 알 수 없습니다.Android가 두 부분으로 나누어집니다.

그림에 대한

나는이 사진 첨부 :

enter image description here

보기 X에 클릭 한 후 하위 뷰를 정확히 아래에 나타납니다 (화면의 나머지 부분은 아래로 이동합니다) :

enter image description here

이 효과를 아는 사람이 있습니까? 인사말!

답변

1

android studio에서 조각을 펼쳐 활동에 추가 할 수 있습니다. 여기

이 예제 : 살펴 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> 

에서

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(); 

      } 
     }); 
    } 
} 

, 나는 아래의보기를 넣어 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); 
}