如何在Tab Fragment中向下滚动webview

时间:2017-11-24 06:56:35

标签: android xml webview fragment

我的Webview在Tab Fragment中实现。我想将网页视图滚动到片段的底部。现在我无法向下滚动片段中的webview。我正在使用android studio来开发它。以下是我的代码:

片段XML:

//MARK: Setting picker select label size

    /**
     Called by Picker to To add customized text to fit size
     - parameter pickerView: The picker view requesting the data.
     - parameter row: Index of row
     - parameter component: component Index
     */

    func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {        
        let pickerLabel = UILabel() //get picker label that come

        pickerLabel.lineBreakMode = .byWordWrapping //Wrapping if needed

        pickerLabel.numberOfLines = 0; //So it comes to single line 

        pickerLabel.textColor = UIColor.white //setting colour 

        self.currentValue = NamesStringArray[row] //Array with Titles

        let data = NamesStringArray[row] //Taking Index Title

        let title = NSAttributedString(string: data, attributes: [NSAttributedStringKey.font : UIFont(name: "Avenir-Heavy", size: 40.0)!]) //here add attributes

        pickerLabel.attributedText = title //setting attributed text as title

        pickerLabel.sizeToFit() //Size to fit //If needed

        pickerLabel.adjustsFontSizeToFitWidth = true //if needed

        return pickerLabel //return value

    }

Activty:

<head>

2 个答案:

答案 0 :(得分:2)

好吧,尝试使用 RelativeLayout ,它会显示为已满。由于constraintLayout:

,您正面临这个问题
<?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"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:paddingBottom= "5dp">

<WebView
android:id="@+id/webview"
android:layout_width="371dp"
android:layout_height="516dp"
tools:layout_editor_absoluteX="-12dp"
tools:layout_editor_absoluteY="-3dp" />
 </RelativeLayout >

答案 1 :(得分:0)

@Umair的回答向我指出了正确的方向,但没有指出要点。我不必更改相对布局即可解决此问题,我的网络视图引发了警告,提示它没有正确约束(请参见红色下划线)

enter image description here

将宽度和高度更改为

<WebView
    android:id="@+id/webView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    tools:layout_editor_absoluteY="1dp" />

问题马上得到解决。现在,这个问题可能只出现在片段中,但这是解决它的一种方法。