我必须将WebView放入ScrollView.但是我必须在webview之前将一些视图放到同一个scrollview中.所以它看起来像这样:
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:id="@+id/articleDetailPageContentLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/articleDetailRubricLine"
android:layout_width="fill_parent"
android:layout_height="3dip"
android:background="@color/fashion"/>
<ImageView
android:id="@+id/articleDetailImageView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitStart"
android:src="@drawable/article_detail_image_test"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dip"
android:text="PUBLISH DATE"/>
<WebView
android:id="@+id/articleDetailContentView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/fashion"
android:isScrollContainer="false"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我从后端获得了一些HTML信息.它没有任何身体或头部标签,只有被<p>或<h4>或其他标签包围的数据.它还有<img>标签.有时图片对于当前屏幕宽度来说太宽.所以我在HTML的开头添加了一些CSS.所以我将数据加载到webview,如下所示:
private final static String WEBVIEW_MIME_TYPE = "text/html";
private final static String WEBVIEW_ENCODING = "utf-8";
String viewport = "<head><meta name=\"viewport\" content=\"target-densitydpi=device-dpi\" /></head>";
String css = "<style type=\"text/css\">" +
"img {width: 100%;}" +
"</style>";
articleContent.loadDataWithBaseURL("http://", viewport + css + articleDetail.getContent(), …Run Code Online (Sandbox Code Playgroud) 我有webview with layout_height ="wrap_content".如果我增加默认字体大小,那么webview高度也会增加.但是如果我减少默认字体大小,那么webview高度不会降低.所以剩下的底部有空的空间.
我试过以下技巧:
articleContent.getSettings().setDefaultFontSize(fontSize);
RelativeLayout.LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
layoutParams.addRule(RelativeLayout.BELOW, subtitleTextView.getId());
articleContent.setLayoutParams(layoutParams);
Run Code Online (Sandbox Code Playgroud)
但它没有帮助.我知道有一种方法可以通过在更改默认字体大小时使用代码重新创建WebView来修复它,但在我的情况下,我不能这样做.我需要保持webview,因为有一些观点,我也无法重新创建它们.
我的 WPF 项目中有一些简单的层次结构。
我有基类,称为产品。然后我从这个基类继承了两个类。然后我从他们两个继承了更多的类。
所以我有 Product 类,然后是 Book 和 Disk 类,它们继承自 Product 类,以及 RecipeBook 类、ProgramingBook 类和 AdventureBook 类,它们继承自 Book 类。
然后我创建集合并在那里添加一些书,比如 collection.Add(new RecipeBook() {bla bla bla});
最后我收集了不同的类。
所以我需要的只是通过 WPF TreeView 显示所有这些东西。
它会是这样的:
Product
Book
RecipeBook
Book#1
Book#2
ProgramingBook
Book#1
....
Disk
Disk#1
Disk#2
.....
Run Code Online (Sandbox Code Playgroud)
那我该怎么做呢?
<TreeView x:Name="treeView" Height="224" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="337" >
<TreeViewItem Header="Products" >
<TreeViewItem Header="Books">
<TreeViewItem Header="Recipe"></TreeViewItem>
<TreeViewItem Header="Programing"></TreeViewItem>
<TreeViewItem Header="Adventure"></TreeViewItem>
</TreeViewItem>
<TreeViewItem Header="CDs">
</TreeViewItem>
</TreeViewItem>
</TreeView>
Run Code Online (Sandbox Code Playgroud) 我有以下布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/item_background"
android:layout_margin="10dip"
android:gravity="center_vertical">
<View
android:layout_width="30dip"
android:layout_height="fill_parent"
android:background="@color/test_color"/>
<ImageView
android:id="@+id/task_item_startstop_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/start_task"
android:layout_centerVertical="true"
android:focusable="false"
android:background="#0000"/>
<View
android:id="@+id/task_item_line"
android:layout_width="2dp"
android:layout_height="40dip"
android:layout_margin="5dip"
android:background="@color/line_color"
android:layout_toRightOf="@id/task_item_startstop_button"/>
<TextView
android:id="@+id/task_item_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@android:color/black"
android:textSize="22sp"
android:textStyle="bold"
android:layout_toRightOf="@id/task_item_line" />
<TextView
android:id="@+id/task_item_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/task_item_suspended"
android:textSize="18sp"
android:textColor="@android:color/black"
android:layout_toRightOf="@id/task_item_line"
android:layout_below="@id/task_item_title"/>
<TextView
android:id="@+id/task_item_timer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dip"
android:textSize="18sp"
android:textColor="@android:color/black"
android:layout_toRightOf="@id/task_item_status"
android:layout_below="@id/task_item_title"/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
我希望在布局的左侧有垂直线(根布局内的第一个视图),其固定宽度和高度等于父级的高度.但是,如果我设置layout_height ="fill_parent"它没有帮助.高度为0.如果我设置高度例如40dip,它将是40倾角.但我需要fill_parent属性.
我需要裁剪角落ImageView.不要围绕它们,而是从每个角落擦除三角形.
似乎唯一的方法是覆盖onDraw方法并从画布中删除这些区域Path.问题是我没有纯色背景,所以我需要删除这些区域,但不要用一些颜色填充它们.
我使用以下代码:
@Override
protected void onDraw(Canvas canvas) {
Path path = new Path();
path.moveTo(0, 0);
path.lineTo(20, 0);
path.lineTo(0, 20);
path.close();
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
canvas.drawPath(path, paint);
super.onDraw(canvas);
}
Run Code Online (Sandbox Code Playgroud)
但角落变黑但不透明.你可以帮帮我吗?或者你可能知道我的任务更好的解决方案.这是它的样子.

如果 webview html 内容几乎没有<img>标签,当用户在 webview 中点击图像时,是否可以在新活动中以全屏模式打开该图像?
android ×5
webview ×2
c# ×1
canvas ×1
erase ×1
fill-parent ×1
hierarchy ×1
layout ×1
path ×1
scrollview ×1
transparency ×1
treeview ×1
wpf ×1