Tools属性Tools Attributes

Android有一个专门的工具类XML命名空间,用于在XML文件中记录信息,而且这些信息会在程序打包时被去掉,所以不会造成运行时和下载的负担。这个命名空间的URI是http://schemas.android.com/tools,常用前缀是tools:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    <strong>xmlns:tools="http://schemas.android.com/tools"</strong>
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    ....
这篇文档记录了我们常用的工具类属性(这可能会经常变 化)。

tools:ignore

这个属性可以应用在任何XML元素上,它的值是用逗号分隔的Lint问题ID,表示该元素及其子元素都忽略这些问题。

<string name="show_all_apps" tools:ignore="MissingTranslation">All</string>

用于:Lint.

tools:targetApi

这个属性就像Java中的@TargetApi注解。它让你指定该元素运行时的API级别,可以是API的数值,也可以示API的名字。

<GridLayout tools:targetApi="ICE_CREAM_SANDWICH" >

用于:Lint.

tools:locale

该属性可以用在资源Value文件的跟元素上,它对应一种语言(可以加上一个区域)。这样工具类就知道文件中的字符串究竟是哪个语言(或者区域的)。举个例子,values/strings.xml 可以这样指定跟元素

<resources xmlns:tools="http://schemas.android.com/tools" <strong>tools:locale="es"</strong>>

这样我们就知道缺省Values文件夹中的使用的语音是西班牙语而不是英语。

用于:Lint,Studio(关闭资源文件中的拼写检查).


其他的就没翻译了:

tools:context

用于layout猜测布局预览时使用的主题。因为主题一般在Manifest文件中指定,而且主题之和Activity关联,而不是layout。
<android.support.v7.widget.GridLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
    <strong>tools:context=".MainActivity"</strong> ... 

tools:layout

用在<fragment>标签上,用于指定设计时设计器渲染的layout。

<fragment android:name="com.example.master.ItemListFragment" <strong>tools:layout="@android:layout/list_content"</strong> />

其他的,就不多说了

tools:listitem /listheader /listfooter

tools:showIn

tools:menu

tools:actionBarNavMode



Designtime Layout Attributes

可以用tools:xxxxx属性指定设计时的android:xxxxx属性。


首先得在布局文件中加上命名空间:

<LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
       <strong> xmlns:tools="http://schemas.android.com/tools"</strong>
        android:layout_width="match_parent"
        ...


举个例子:想在设计时,让TextView显示“aaa”,而在正式运行时不显示该字符串。只要这样:

<TextView 
     <strong>       tools:text="aaa"</strong>
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />







  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以使用Geotools库来读写shp文件。下面是一个简单的示例代码,可以读取shp文件并打印出其属性表信息: ```java import java.io.File; import java.io.IOException; import org.geotools.data.DataStore; import org.geotools.data.DataStoreFinder; import org.geotools.data.simple.SimpleFeatureCollection; import org.geotools.data.simple.SimpleFeatureIterator; import org.opengis.feature.simple.SimpleFeature; import org.opengis.feature.simple.SimpleFeatureType; public class ShpFileReader { public static void main(String[] args) throws IOException { // 读取shp文件 File file = new File("path/to/shapefile.shp"); DataStore dataStore = DataStoreFinder.getDataStore(file); String typeName = dataStore.getTypeNames()[0]; SimpleFeatureType schema = dataStore.getSchema(typeName); // 获取属性表信息 System.out.println("Feature Type: " + typeName); System.out.println("Number of attributes: " + schema.getAttributeCount()); System.out.println("Attributes: "); for (int i = 0; i < schema.getAttributeCount(); i++) { System.out.println(schema.getAttributeDescriptors().get(i).getName()); } // 获取要素信息 SimpleFeatureCollection collection = dataStore.getFeatureSource(typeName).getFeatures(); try (SimpleFeatureIterator features = collection.features()) { while (features.hasNext()) { SimpleFeature feature = features.next(); System.out.println(feature.getID() + ": " + feature.getDefaultGeometryProperty().getValue()); } } dataStore.dispose(); } } ``` 需要注意的是,需要在pom.xml中添加geotools依赖: ```xml <dependency> <groupId>org.geotools</groupId> <artifactId>gt-shapefile</artifactId> <version>24.0</version> </dependency> ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值