3

enter image description here안드로이드 FrameLayout이 가능한 모든 공간을 사용

안녕 모두, 나는 다른 이미지와 텍스트 (둘 다 조각 내에서 호스팅)와 (에어 비앤비 응용 프로그램에서이 같은)는 "튜토리얼"만들려고 해요 FrameLayout 내부의 (Fragment) ViewPager에 의해 관리된다. 위 예제에서 두 개의 버튼을 화면 하단에 표시하고 싶습니다. 내 문제는 ViewPager가 포함 된 FrameLayout이 사용 가능한 모든 공간을 차지하므로 단추가 들어있는 LinearLayout이 숨겨져 있다는 것입니다.

레이아웃이 매우 간단하므로 여러 가지 방법을 시도했지만 아무런 문제가 해결되지 않는 이상한 상황입니다. 레이아웃의 루트 요소 만 fill_parent 모드에 있고 다른 모든 레이아웃이 정보를 표시하는 데 필요한 공간을 초과하지 않도록 확인했는지 확인했습니다.

는 여기에 몇 가지 조각이다, 활동과 FragmentViewPager에 의해 표시되는 각 자식 조각에 대한 XML 레이아웃 :

활동 tutorial.xml (I 대신 RelativeLayout의의 루트 요소로있는 LinearLayout으로 해봤이 하나, 하지만 아무것도

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 

<FrameLayout 
    android:id="@+id/pager_framelayout" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 

    <android.support.v4.view.ViewPager 
     android:id="@+id/tutorial_pager" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" /> 

    <com.viewpagerindicator.CirclePageIndicator 
     android:id="@+id/circle_indicator" 
     android:padding="@dimen/general_padding" 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" 
     android:background="@null" 
     android:layout_gravity="bottom" /> 
</FrameLayout> 

<LinearLayout 
    android:id="@+id/buttons_bottom_layout" 
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent" 
    android:orientation="horizontal" 
    android:weightSum="100" 
    android:layout_below="@id/pager_framelayout"> 

    <Button 
     android:id="@+id/sign_up_btn" 
     android:padding="@dimen/general_padding" 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" 
     android:layout_weight="50" 
     android:text="Sign UP" /> 

    <Button 
     android:id="@+id/login_btn" 
     android:padding="@dimen/general_padding" 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" 
     android:layout_weight="50" 
     android:text="Login" /> 
</LinearLayout> 
</RelativeLayout> 

fragment_tutorial_screen.xml

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:orientation="vertical" > 

<ImageView 
    android:id="@+id/tutorial_screen_image" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:scaleType="centerCrop"/> 

<TextView 
    android:id="@+id/tutorial_screen_title" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:padding="@dimen/general_padding" 
    android:background="@null" 
    android:layout_gravity="bottom"/> 
</FrameLayout> 
) 변경되지 않습니다

그리고 인스턴스화 조각의 자바 코드와 정보와 전망을 채울 :

TutorialScreenFragment.java을

{ //... 
@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
     Bundle savedInstanceState) { 
    // Identify and set fields! 
    ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.subfragment_tutorial_screen, container, false); 
    image = (ImageView) rootView.findViewById(R.id.tutorial_screen_image); 
    title = (TextView) rootView.findViewById(R.id.tutorial_screen_title); 
    return rootView; 
} 

@Override 
public void onActivityCreated(Bundle savedInstanceState) { 
    super.onActivityCreated(savedInstanceState); 
    // Populate fields with info! 
    if (TutorialActivity.class.isInstance(getActivity())) { 
     title.setText(titleResId); 
     // Call Glide to load image 
     Glide.with(this) 
     .load(imageResId) 
     .centerCrop() 
     .placeholder(R.drawable.image_placeholder) 
     .into(image); 
    } 
} 
/... 
} 

모든는 점은 현재 페이지를 표시 느릅 나무, 잘 작동하지만 버튼은 때로 믿을 수 전혀 표시되지 않습니다.

enter image description here

감사 : 이것은 내 응용 프로그램의 결과입니다.

답변

2

레이아웃의 동작을 변경해야합니다. 먼저 부모의 하단에 LinearLayout을 맞 춥니 다. 그런 다음 FrameLayoutLinearLayout 위에 올려 놓습니다. 다음과 같은 것 :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 

<FrameLayout 
    android:id="@+id/pager_framelayout" 
    android:layout_width="fill_parent" 
    android:layout_above="@+id/buttons_bottom_layout" 
    android:layout_height="wrap_content"> 

    <android.support.v4.view.ViewPager 
     android:id="@+id/tutorial_pager" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" /> 

    <com.viewpagerindicator.CirclePageIndicator 
     android:id="@+id/circle_indicator" 
     android:padding="@dimen/general_padding" 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" 
     android:background="@null" 
     android:layout_gravity="bottom" /> 
</FrameLayout> 

<LinearLayout 
    android:id="@+id/buttons_bottom_layout" 
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent" 
    android:orientation="horizontal" 
    android:weightSum="100" 
    android:layout_alignParentBottom="true"> 

    <Button 
     android:id="@+id/sign_up_btn" 
     android:padding="@dimen/general_padding" 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" 
     android:layout_weight="50" 
     android:text="Sign UP" /> 

    <Button 
     android:id="@+id/login_btn" 
     android:padding="@dimen/general_padding" 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" 
     android:layout_weight="50" 
     android:text="Login" /> 
</LinearLayout> 
</RelativeLayout> 
+0

나는 android : layout_alignParentBottom = "true"를 사용해야했습니다. 굉장해! 감사! 왜 이런 일이 발생하는지 알고 있습니까?이 상황을 설명하는 온라인 리소스가 있습니까? 다시 한번 감사드립니다. – fiipi

+0

그래, 틀림없이 'android : layout_alightParentBottom = "true"', 내 실수 야. 귀하의'ViewPager'는 전체 화면 이었기 때문에 하단 버튼이'ViewPager' 아래에 있었는데, 이것은 스크린 밖 이었음을 의미합니다. – rom4ek

+0

굉장합니다, 고마워요! – fiipi

관련 문제