2017-05-15 2 views
-1

Ich benutze Webview in Android für die Anzeige von Artikeln auch der Bildschirm hat nächste vorherige Schaltflächen, um die Artikel zu navigieren. Wenn der Inhalt weniger ist, müssen die nächsten Schaltflächen am unteren Bildschirmrand angezeigt werden, und wenn der Inhalt riesig ist, müssen diese Schaltflächen am Ende des Inhalts angezeigt werden.Android ScrollView UI

Wie kann ich das umsetzen? Zur Zeit mache ich etwas wie folgt vor:

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



    <ScrollView 
     android:layout_width="fill_parent" 
     android:layout_height="match_parent"> 
     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical"> 
      <LinearLayout 
       android:orientation="vertical" 
       android:layout_width="match_parent" 
       android:layout_weight="1" 
       android:layout_height="wrap_content" 
       android:padding="4dp"> 
       <TextView 
        android:id="@+id/article_title" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:textSize="16dp" 
        android:text="ARTICLE NAME" 
        android:textColor="@color/colorPrimaryDark" 
        android:layout_weight="1" 
        android:gravity="center_vertical" 
        android:paddingLeft="4dp" 
        /> 
       <TextView 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:textSize="12dp" 
        android:text="Published date" 
        android:textColor="@color/colorSecondaryText_GRAY" 
        android:layout_weight="1" 
        android:id="@+id/article_publish_text" 
        android:paddingLeft="4dp" 
        /> 
       <TextView 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:textSize="12dp" 
        android:text="FOLDER NAME" 
        android:textColor="@color/colorSecondaryText_GRAY" 
        android:layout_weight="1" 
        android:id="@+id/article_folder_name_text" 
        android:paddingLeft="4dp" 
        /> 

      </LinearLayout> 

      <WebView 
       android:id="@+id/pageInfo" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:background="@drawable/border_set"></WebView> 

      <RelativeLayout 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:orientation="horizontal" 
       android:layout_margin="4px" 
       android:padding="4px" 
       > 
       <Button 
        android:id="@+id/button_prev" 
        android:layout_gravity="left" 
        android:layout_alignParentLeft="true" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:background="@drawable/button_selector" 
        android:textColor="@color/colorPrimary" 
        android:text="Previous" /> 

       <Button 
        android:id="@+id/button_next" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginLeft="2px" 
        android:layout_gravity="right" 
        android:layout_alignParentRight="true" 
        android:background="@drawable/button_selector" 
        android:textColor="@color/colorPrimary" 
        android:text="Next" /> 

      </RelativeLayout> 

     </LinearLayout> 
    </ScrollView> 
     </LinearLayout> 

für seine jetzt korrekt arbeitet für große Inhalte, sondern für kurze Inhalt dich Tasten direkt unter dem Inhalt angezeigt bekommen, und ich möchte, dass sie am unteren Rand des Bildschirms

Antwort

0

können Sie Fügen Sie die nächste und vorherige Schaltfläche am unteren Rand des übergeordneten linearen Layouts hinzu.

+1

Ist das wie ein Zauberspruch helfen? Weil es auf Englisch nichts bedeutet ... – 2Dee

0

ScrollView auf Aktivität erweitern und Schaltfläche sichtbar machen, wenn Diff == 00 den Butoon unsichtbar setzen nur sichtbar, wenn ganze Seite geschrollt wird. hoffe es wird dir helfen.

@Override 
protected void onScrollChanged(int l, int t, int oldl, int oldt) 
{ 
    // Grab the last child placed in the ScrollView, we need it to determinate the bottom position. 
    View view = (View) getChildAt(getChildCount()-1); 

    // Calculate the scrolldiff 
    int diff = (view.getBottom()-(getHeight()+getScrollY())); 

    // if diff is zero, then the bottom has been reached 
    if(diff == 0) 
    { 

     // make button visible here 
     // notify that we have reached the bottom 
     Log.d(ScrollTest.LOG_TAG, "MyScrollView: Bottom has been reached"); 
    } 

    super.onScrollChanged(l, t, oldl, oldt); 
} 
0

Sie unter Struktur verwenden können Ansicht zu implementieren:

<RelativeLayout 
. 
. 
.> 
<LinearLayout 
. 
. 
align_parent_top=true 
id = top_layout> 
//Content 
</LinearLayout> 

<WebView 
. 
. 
layout_above = bottom_layout 
layout_below = top_layout 
. 
id = web_view/> 

<LinearLayout 
. 
. 
. 
id = bottom_layout 
align_parent_bottom=true> 
//content 
</LinearLayout> 

</RelativeLayout> 

Hope this you .. :)