【问题标题】:Android viewpager not displayed in case other objects dynamically inflated below itAndroid viewpager 不显示,以防其他对象在其下方动态膨胀
【发布时间】:2015-11-03 12:26:07
【问题描述】:

我正在开发特定类型的日历,显示某些日子的事件,并在日历下方显示相关月份的事件列表。为此,我受益于Caldroid。这是主要的xml文件:

 <?xml version="1.0" encoding="utf-8"?>
 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  tools:context="com.vbs.android.caltest.MainActivity"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:fadingEdgeLength="0dp"
  android:fillViewport="true"
  android:overScrollMode="never"
  android:orientation="vertical">

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

  <LinearLayout
      android:id="@+id/calendar1"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_weight="1"
      android:orientation="vertical"/>



  <LinearLayout
      android:id="@+id/eventsList"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_weight="1"
      android:orientation="vertical"/>
 </LinearLayout>
</ScrollView>

进入 calendar1 Caldroid 被安排。这是 Caldroid xml 文件:

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

<LinearLayout
    android:id="@+id/calendar_title_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <Button
        android:id="@+id/calendar_left_arrow"
        style="?styleCaldroidLeftArrow" />

    <TextView
        android:id="@+id/calendar_month_year_textview"
        style="?styleCaldroidMonthName"/>

    <Button
        android:id="@+id/calendar_right_arrow"
        style="?styleCaldroidRightArrow" />
  </LinearLayout>

  <GridView
    android:id="@+id/weekday_gridview"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="-10dp"
    android:numColumns="7"
    android:stretchMode="columnWidth" >
   </GridView>

  <com.antonyt.infiniteviewpager.InfiniteViewPager
    android:id="@+id/months_infinite_pager"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"/>




</LinearLayout>

所以,Caldroid 应用程序的屏幕截图是:

问题是当我尝试将事件膨胀到 eventsList(LinearLayout) 时,日历的 viewpager 部分没有显示。我使用以下方法将 3 个 textViews 膨胀到 eventsList 中:

   public void eventListFiller(){
    eventInflater = 
    (LayoutInflater)this.getSystemService(this.LAYOUT_INFLATER_SERVICE);
    eventsContainer = (LinearLayout) findViewById(R.id.eventsList);
    View eventContent;

    for (int i=0; i<array.length; i++){
        eventContent = eventInflater.inflate(R.layout.event_list, null);
        TextView startDateTextView = 
      (TextView)   eventContent.findViewById(R.id.startDateTextView);
        TextView endDateTextView = 
     (TextView)   eventContent.findViewById(R.id.endDateTextView);
        TextView eventTitle =(TextView)eventContent.
        findViewById(R.id.titleTextView);
        startDateTextView.setText("startDate");
        endDateTextView.setText("endDate");
        eventTitle.setText(array[i]);
        eventsContainer.addView(eventContent);
    }

    Log.d("Runned", "EventsListFilled");
 }

帮我看看这里有什么问题。提前谢谢你。

【问题讨论】:

  • 非常感谢 Bence,我通过 Mielet (github.com/mielet) 的方法解决了这个问题。

标签: java android android-viewpager scrollviewer layout-inflater


【解决方案1】:

考虑更灵活的库DureyCalendarView。它不使用 Fragment,您可以随时放置自定义视图,并且可以轻松定义 XML 布局。

【讨论】:

  • 非常感谢 Bence,我通过 Mielet (github.com/mielet) 的方法解决了这个问题
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-11
  • 1970-01-01
  • 1970-01-01
  • 2022-06-10
  • 1970-01-01
相关资源
最近更新 更多