我的布局中有这个ImageView:
<ImageView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:contentDescription="@string/image_divider"
android:paddingBottom="8dp"
android:paddingTop="4dp"
android:scaleType="fitXY"
android:src="@android:drawable/divider_horizontal_textfield" />
Run Code Online (Sandbox Code Playgroud)
这是一个水平分隔线.我想将它旋转90度,所以我有一个垂直分隔线.
有没有可能的方法在布局而不是Activity类中执行此操作?
我在java中做了一段代码,我需要获得不同大小的文件系统图标.我知道要获取文件系统图标,我应该使用这个:
File file = new File("Whatever.txt");
FileSystemView view = FileSystemView.getFileSystemView();
Icon icon = view.getSystemIcon(file);
Run Code Online (Sandbox Code Playgroud)
但此代码返回最小的图标大小.我为获得其他尺码做了什么?
我正在开发一款使用局域网的游戏.像大多数多人游戏一样,有一个服务器 - 客户端系统.计算机A运行程序实例,创建服务器并等待; 计算机B做同样的事情.现在Computer C运行程序,我想要的是他可以看到计算机A和B在那里列为游戏服务器.我怎样才能做到这一点?
为了列出所有可用的服务器,一个简单的解决方案可能就是:我需要检查特定范围内的所有IP地址,看看它们是否通过我的特定端口进行响应.如果是,那么就会在其上运行一个游戏实例,并且应该列在服务器列表中.
上面描述的解决方案是好的吗?我搜索并得到这段代码:
public void checkHosts(String subnet){
int timeout=1000;
for (int i=1;i<254;i++){
String host=subnet + "." + i;
if (InetAddress.getByName(host).isReachable(timeout)){
System.out.println(host + " is reachable");
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是花了很多时间而且没用.如果它不是正确的解决方案,还有什么其他方法?
我正在开发一款Android应用.我按照Sugar ORM网站上的说明创建了一个数据库表.我做的一切都是一样的,我已经仔细检查了一下.
问题是,当应用程序在Android 5.0或更高版本上运行时,执行查询时,它会抛出SQLiteException并且不会显示此类表.相同的代码在KitKat设备上执行正常,并导致正确的结果,没有任何异常.
Sugar ORM支持Andriod 5.0吗?
我想通过layoutInflater将布局放到另一个布局中.
这是main_layout.xml文件:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/ads_image_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="@drawable/ic_launcher" />
<RelativeLayout
android:id="@+id/host_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/navigation_buttons_layout"
android:layout_alignParentLeft="true"
android:layout_below="@+id/ads_image_view" >
</RelativeLayout>
<RelativeLayout
android:id="@+id/navigation_buttons_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="Button" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
这是vitrin_layout.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ff0000"
android:text="smallred" />
Run Code Online (Sandbox Code Playgroud)
最后我的主要活动的onCreate方法:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_layout);
ViewGroup parent = (ViewGroup) findViewById(R.id.host_layout);
View view = LayoutInflater.from(getBaseContext()).inflate(
R.layout.vitrin_layout, null);
parent.addView(view, LayoutParams.FILL_PARENT);
setTitle(getString(R.string.title_activity_vitrin));
}
Run Code Online (Sandbox Code Playgroud)
问题是vitrin_layout不适合其父(host_layout); 虽然我已经设置了fill_parent! …