我试图像在Eclipse中那样在Android Studio中使用自定义字体.但遗憾的是无法找出放置'assets'文件夹的位置!
在java中,我们可以像这样创建对象的arraylist:
ArrayList<Country> countryList = new ArrayList<Country>();
Country aBucket = new Country();
aBucket.setName("Canada");
aBucket.setCity("Ottawa");
countryList.add(aBucket);
Run Code Online (Sandbox Code Playgroud)
或者像这样:
ArrayList<Matrices> list = new ArrayList<Matrices>();
list.add( new Matrices(1,1,10) );
list.add( new Matrices(1,2,20) );
Run Code Online (Sandbox Code Playgroud)
但是我怎样才能在SWIFT中获得相同的东西/替代品
UIStackView
类似于Android,LinearLayout
但我无法弄清楚如何为子视图设置权重.
假设我有一个垂直UIStackView
和3 UIImageView
秒.我想连续为UIImageView
s 设置权重3,6,1 .我怎么做?
在 CardView 中使用圆角时,在圆角区域显示白色边框,这在黑暗环境中最常见。为了更容易理解,请检查附加的图像吹。
这是 xml
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorTransparent"
android:orientation="vertical"
android:padding="4sp">
<androidx.cardview.widget.CardView
android:id="@+id/image_view_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginBottom="20dp"
android:background="@color/colorTransparent"
app:cardCornerRadius="20dp"
app:cardElevation="4dp">
<ImageView
android:id="@+id/iv_themes"
android:layout_width="match_parent"
android:layout_height="110dp"
android:background="@color/colorTransparent"
android:gravity="center"
android:scaleType="centerCrop"
android:src="@mipmap/tm_2_mip_background" />
</androidx.cardview.widget.CardView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我有一个可以使用DragGesture()拖动的图像。我想裁剪矩形区域内可见的图像。这是我的代码...
struct CropImage: View {
@State private var currentPosition: CGSize = .zero
@State private var newPosition: CGSize = .zero
var body: some View {
VStack {
ZStack {
Image("test_pic")
.resizable()
.scaledToFit()
.offset(x: self.currentPosition.width, y: self.currentPosition.height)
Rectangle()
.fill(Color.black.opacity(0.3))
.frame(width: UIScreen.screenWidth * 0.7 , height: UIScreen.screenHeight/5)
.overlay(Rectangle().stroke(Color.white, lineWidth: 3))
}
.gesture(DragGesture()
.onChanged { value in
self.currentPosition = CGSize(width: value.translation.width + self.newPosition.width, height: value.translation.height + self.newPosition.height)
}
.onEnded { value in
self.currentPosition = CGSize(width: value.translation.width + self.newPosition.width, height: value.translation.height + self.newPosition.height)
self.newPosition …
Run Code Online (Sandbox Code Playgroud) 我想通过一个小矩形使图像 100% 透明,并使所有其他图像 50% 透明。好像打了一个小孔来透视这个小矩形。这是我的代码...
struct ImageScope: View {
var body: some View {
ZStack {
Image("test_pic")
Rectangle()
.foregroundColor(Color.black.opacity(0.5))
Rectangle()
.frame(width: 200, height: 150)
.foregroundColor(Color.orange.opacity(0.0))
.overlay(RoundedRectangle(cornerRadius: 3).stroke(Color.white, lineWidth: 3))
}
}
}
Run Code Online (Sandbox Code Playgroud)
为了更容易理解...
我想加粗每一行的第一个字.而不是大胆它显示整个代码!
private void addAsimA(ArrayList<String> products) {
products.add("<b>Apple</b> It is red");
products.add("<b>Banana</b> It is yellow");
products.add("<b>Mango</b> It is green");
Run Code Online (Sandbox Code Playgroud)
我怎样才能得到这样的输出:
Apple它是红色的
香蕉它是黄色的
芒果它是绿色的
这是完整的java文件
public class MainActivity extends Activity {
TextView txtv, txt1;
ImageView imgv;
// List view
private ListView lv;
// Listview Adapter
ArrayAdapter<String> adapter;
// ArrayList for Listview
ArrayList<HashMap<String, String>> productList;
ArrayList<String> products = new ArrayList<String>();
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addAsimA(products);
addAsimB(products);
} …
Run Code Online (Sandbox Code Playgroud) 我希望借助此答案从网页中删除"header"元素在webview android上显示网页的一部分
但我收到一条错误消息; 请参阅此https://dl.dropboxusercontent.com/u/15065300/Check-2.jpg
这是我的完整代码:
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class WebViewActivity extends Activity {
private WebView webView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
webView = (WebView) findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url)
{
webView.loadUrl("javascript:(function() { " +
"document.getElementsByTagName('myDiv1')[0].style.display="none"; " +
"})()");
}
});
webView.loadUrl("http://skyasim.info/abc.html");
}
}
Run Code Online (Sandbox Code Playgroud)
显示许可也是如此
<uses-permission android:name="android.permission.INTERNET" />
Run Code Online (Sandbox Code Playgroud) 我想在 webview android 上部分查看网页并从网页中删除一些 div 元素。我有一个这样的网页
<!DOCTYPE html>
<body>
<div id="a"><p>Remove aa</p></div>
<div id="b"><p>bb</p></div>
</body></html>
Run Code Online (Sandbox Code Playgroud)
现在我想从网页中删除 id 为 'a' 的 div。
我尝试用 Jsoup 对其进行编码,但我还不够好,无法弄清楚。请看我的完整代码:
import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import android.os.Bundle;
import android.app.Activity;
import android.graphics.Bitmap;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class CustomWebsite extends Activity {
private WebView webView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_custom_website);
Document doc;
String htmlcode = "";
try {
doc = Jsoup.connect("http://skyasim.info/ab.html").get();
doc.head().getElementsByTag("DIV#a").remove();
htmlcode = doc.html();
} catch (IOException e) {
// TODO Auto-generated catch …
Run Code Online (Sandbox Code Playgroud) 我有一个AnyObject类型的数组,如下所示:[[String:AnyObject]]
animalList = [["name":ABC,"color":red],["name":DEF,"color":green],["name":GHI,"color":blue]]
模型类是这样的:
class ModelAnimal {
var name: String
var color: String
init(name: String, color: String){
self.name = name
self.color = color
}
}
Run Code Online (Sandbox Code Playgroud)
如何将它们放在ModelAnimal类型的数组中:
var myList = Array<ModelAnimal>()
for var i = 0; i < animalList.count; i++ {
myList.
}
Run Code Online (Sandbox Code Playgroud)