fadingEdge和fadingEdgeLength属性

随时随地阅读更多技术实战干货,获取项目源码、学习资料,请关注源代码社区公众号(ydmsq666)

fadingEdge属性用来设置拉滚动条时 ,边框渐变的放向。none(边框颜色不变),horizontal(水平方向颜色变淡),vertical(垂直方向颜色变淡)。

fadingEdgeLength用来设置边框渐变的长度。

测试示例:

MainActivity:

package com.home.testedge;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		ListView lv = (ListView) findViewById(R.id.main_list);
		// 在代码里设置边框渐变宽度
		// lv.setFadingEdgeLength(0);
		// 去掉分割黑线
		lv.setDivider(null);
		String[] data = new String[] { "item1", "item2", "item3", "item4",
				"item5", "item6", "item7", "item8", "item9", "item10",
				"item11", "item12" };
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1, data);
		lv.setAdapter(adapter);
	}
}

布局xml:

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

    <!-- fadingEdge:拉滚动条时 ,边框渐变的放向,none(边框颜色不变),horizontal(水平方向颜色变淡),vertical(垂直方向颜色变淡) -->
    <!-- fadingEdgeLength:设置边框渐变的长度 -->

    <ListView
        android:id="@+id/main_list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fadingEdge="vertical"
        android:fadingEdgeLength="200dp" />

</LinearLayout>



 

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
可以通过继承 Preference 类来实现自定义布局,并在其中添加一个 Button,然后为该 Button 添加点击事件。下面是一个简单的示例代码: ```java public class CustomPreference extends Preference { private Button mButton; public CustomPreference(Context context, AttributeSet attrs) { super(context, attrs); setWidgetLayoutResource(R.layout.custom_preference); } @Override public void onBindViewHolder(PreferenceViewHolder holder) { super.onBindViewHolder(holder); mButton = (Button) holder.findViewById(R.id.custom_button); mButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // 处理点击事件 } }); } } ``` 在布局文件 `custom_preference.xml` 中添加一个 Button: ```xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="?android:attr/listPreferredItemHeight" android:gravity="center_vertical" android:paddingStart="?android:attr/listPreferredItemPaddingStart" android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"> <TextView android:id="@android:id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceListItem" android:singleLine="true" android:ellipsize="marquee" android:fadingEdge="horizontal" android:textColor="@android:color/primary_text_light" /> <Button android:id="@+id/custom_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" /> </LinearLayout> ``` 最后,在设置界面的 XML 文件中使用自定义的 Preference: ```xml <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> ... <com.example.CustomPreference android:key="custom_preference" android:title="Custom Preference" /> </PreferenceScreen> ``` 这样就可以在设置界面中显示一个自定义布局的 Preference,其中包含一个 Button,并且为该 Button 添加了点击事件。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值