【问题标题】:display ViewPager (swipe tab) below Relative layout (not attached to ActionBar )android在相对布局(未附加到 ActionBar )下方显示 ViewPager(滑动选项卡)android
【发布时间】:2014-12-18 12:46:08
【问题描述】:

我的布局有一些视图(EditText 内的EditTextTextview),在下面我需要显示 ViewPager(滑动选项卡),但 android 支持 ViewPager 附加到 ActionBar ,这在我的情况下不是必需的.

当前结果:ActionBar --> ViewPager

预期结果:ActionBar --> RelativeLayout --> ViewPager

如果需要代码我可以发布..

main.xml

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

    <RelativeLayout
        android:id="@+id/container_top_news"
        android:layout_alignParentTop="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <include
            android:id="@+id/top_news"
            layout="@layout/top_news"/>

    </RelativeLayout>

    <android.support.v4.view.ViewPager 
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/container_top_news">
    </android.support.v4.view.ViewPager>

</RelativeLayout>

top_news.xml

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

     <View
                android:id="@+id/view1"
                android:layout_width="match_parent"
                android:layout_height="1dp"              
                android:background="@color/border" 
                android:layout_margin="0dip"/>
    <RelativeLayout
        android:id="@+id/lay_rel_main"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:background="@color/title_background"
        >

         <ImageView
                android:id="@+id/img_photo"
                android:layout_width="150dp"
                android:layout_height="150dp"
                android:layout_below="@+id/view2"
                android:adjustViewBounds="true"               
                android:background="@drawable/ic_getimage"                            
                android:padding="10dip" />

         <View
                android:id="@+id/view2"
                android:layout_width="1dp"
                android:layout_height="match_parent"
               android:layout_toRightOf="@+id/img_photo"
                android:background="@color/border" 
                android:layout_margin="0dip"/>


          <com.rb.lined.edittext.LinedEditText
                android:id="@+id/edit_story"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"                
                android:background="@null"
                android:inputType="textMultiLine|textNoSuggestions"
                android:padding="10dip" 
                android:singleLine="false"
                android:imeOptions="actionNone"

                android:textSize="10sp"
                android:gravity="top|left"              
                app:typeface="roboto_condensed"
               android:layout_toRightOf="@+id/view2"
               android:minLines="10"/>

    </RelativeLayout>

     <View
                android:id="@+id/view3"
                android:layout_width="match_parent"
                android:layout_height="1dp"              
                android:background="@color/border" 
                android:layout_margin="0dip"/>

</RelativeLayout>

【问题讨论】:

    标签: android android-actionbar android-viewpager


    【解决方案1】:

    您目前拥有: 相对布局 - 热门新闻 - ViewPager 由于您没有在子级上设置任何相对布局选项,因此它们都将呈现在外部布局(即屏幕)的左上角(或实际上是顶部开始)。

    如果您将 RelativeLayout 更改为具有垂直方向的 LinerLayout,那么您将在 top_news 下获得 ViewPager。

    【讨论】:

      【解决方案2】:

      你可以试试这个:

      <?xml version="1.0" encoding="utf-8"?>
      <RelativeLayout
          xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:layout_height="match_parent" >
      
          <RelativeLayout
              android:id="@+id/container_top_news"
              android:layout_alignParentTop="true"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content">
      
              <include
                  android:id="@+id/top_news"
                  layout="@layout/top_news"/>
      
          </RelativeLayout>
      
          <android.support.v4.view.ViewPager
              android:id="@+id/pager"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:layout_below="@+id/container_top_news">
          </android.support.v4.view.ViewPager>
      
      </RelativeLayout>
      

      【讨论】:

      • top_news.xml 出现在 viewpager ... 查看我的代码更新和结果截图
      • 没有。事实上,top_news.xml 位于 tabHost 之下和 viewPager 之上,因为在你的情况下 viewpager 是 tabHost 的不同组件。 tabHost 代码在哪里?它不见了。拜托,你能添加一张图片或其他东西来解释你想要做什么吗?所以我会更好地帮助你:)
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多