如何在Android布局文件中定义带下划线的文本xml?
我想在我的上面只添加一个底部和一个顶部边框Linearlayout.我试过这样做:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:bottom="1dp"
android:top="1dp">
<shape android:shape="rectangle">
<solid android:color="#FFFFFF" />
<stroke
android:width="1dp"
android:color="#000" />
</shape>
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)
但它在形状周围添加了边框..
请问你能帮帮我吗 ?
有没有办法为渐变定义顶部和底部笔划,或创建复合形状可绘制?:
// option1:
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#f00"
android:endColor="#0f0"
/>
<stroke
top=1dip, yellow
bottom=1dip, purple
/>
</shape>
// option2
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<shape
android:shape="rectangle"
height=1dip, color=yellow />
<gradient
android:startColor="#f00"
android:endColor="#0f0"
/>
<shape
android:shape="rectangle"
height=1dip, color=purple />
</shape>
Run Code Online (Sandbox Code Playgroud)
我认为两者都不可能吗?
谢谢
<LinearLayout
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="vertical" android:background="@drawable/settings_border" android:padding="1dp"
android:layout_marginLeft="15dip" android:layout_marginRight="15dip" android:layout_marginTop="5dip">
<RelativeLayout android:id="@+id/map_refresh"
android:layout_height="fill_parent" android:layout_width="wrap_content"
android:background="@drawable/settings_selector_up"
android:padding="15dp">
<TextView android:id="@+id/Text1"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:text="Map refresh period">
</TextView>
<TextView android:id="@+id/TextView09"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:text="1 min"
android:layout_alignParentRight="true"
android:paddingRight="5dp">
</TextView>
</RelativeLayout>
<RelativeLayout android:id="@+id/own_location"
android:layout_height="fill_parent" android:layout_width="wrap_content"
android:padding="15dp"
android:background="@drawable/settings_selector_mid">
<TextView android:id="@+id/Text1"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:text="Own location update period">
</TextView>
<TextView android:id="@+id/TextView09"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:text="1 min"
android:layout_alignParentRight="true"
android:paddingRight="5dp">
</TextView>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
我想在relativelayout中只设置底部边框.我想显示listview样式但不使用listview.让我们说每个listitem是相对布局的.我想只设置底部边框,所以它看起来像listview的分隔符.
我看到了许多相关的讨论,但没有找到合适的解决方案.我需要做的是在EditText小部件的顶部和底部创建一个黑色边框.那可能吗?
这是我的XML代码工作正常,唯一的问题是它在所有四个边显示边框,而我只想在顶部和底部显示边框.我怎样才能做到这一点?
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#FFFFFF" />
<stroke
android:width="3dip"
android:color="#B1BCBE"
/>
<padding
android:bottom="0dip"
android:left="0dip"
android:right="0dip"
android:top="0dip"
/>
</shape>
Run Code Online (Sandbox Code Playgroud) 我发现要在视图周围添加边框,我可以使用以下代码作为视图的背景:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF" />
<stroke android:width="1dp" android:color="#999999" />
<padding android:left="1dp" android:top="1dp" android:right="1dp"
android:bottom="1dp" />
</shape>
Run Code Online (Sandbox Code Playgroud)
但是如果我想要一个仅用于底部或顶部或右侧或左侧的边框怎么办?我尝试了以下方法:
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke android:color="#000"/>
</shape>
Run Code Online (Sandbox Code Playgroud)
但是当我把它设置为背景时
android:background="@drawable/my_border"
Run Code Online (Sandbox Code Playgroud)
它在视图的中间绘制线条,所以我有一个穿透效果.有什么方法可以在底部或顶部绘制这条线或使其垂直?
在WPF中,我们有一个形状的相对坐标,所以我可以根据需要偏移线.Android上有类似的东西吗?如果我们没有边框,至少我们应该有好的线形绘图工具,所以我们可以根据需要绘制边框.Android开发者是否计划对此采取行动?
我使用这个例子并试图以编程方式将它添加到我的编辑文本中editText.setBackgroundResource(R.drawable.edit_text_back);,但它不起作用.我怎么能做到这一点?有什么建议或想法吗?
编辑 editText也是以编程方式定义的.
EditText editText = new EditText(this.getApplicationContext());
Run Code Online (Sandbox Code Playgroud)
我把它添加到表格行
受审
editText.setBackground(getResources().getDrawable(R.drawable.edit_text_back));
editText.setBackgroundDrawable(getResources().getDrawable(R.drawable.edit_text_back));
Run Code Online (Sandbox Code Playgroud)
编辑文本创建
TableRow row = (TableRow) findViewById(R.id.table_row_kind);
TableRow.LayoutParams rowP = new TableRow.LayoutParams();
rowP.setMargins(10, 0, 0, 0);
editText = new EditText(this.getApplicationContext());
editText .setGravity(Gravity.FILL_HORIZONTAL);
editText .setLayoutParams(rowP);
editText .setFilters(new InputFilter[]{txtFilter});
editText.setBackground(getResources().getDrawable(R.drawable.edit_text_back));
Run Code Online (Sandbox Code Playgroud)
row.xml
<TableRow
android:id="@+id/table_row_kind"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dip" >
<TextView
android:layout_width="250sp"
android:text="Kind"
android:textAppearance="?android:attr/textAppearanceLarge" />
</TableRow>
Run Code Online (Sandbox Code Playgroud)