期望:
我想在public class MainActivity extends AppCompatActivity {
SwipeRefreshLayout swipeRefreshLayout;
TextView DateView;
TextView tvtitle;
SimpleDateFormat sdf;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
swipeRefreshLayout = findViewById(R.id.swipe_test);
tvtitle = findViewById(R.id.tv_title);
DateView = findViewById(R.id.tv_date);
sdf = new SimpleDateFormat("dd.MM.yyyy - HH:mm:ss z");
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
getDate();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
swipeRefreshLayout.setRefreshing(false);
}
},1500);
}
});
}
public void getDate(){
String currentDateandTime = sdf.format(new Date());
DateView.setText(currentDateandTime);
}
}
的顶部(仅在顶部)像黑色阴影一样产生效果。我尝试为ImageView
的背景创建形状,如下所示:
ImageView
但是它不起作用。有解决方案吗?
答案 0 :(得分:0)
活动或片段的布局
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/ic_launcher_background"
android:adjustViewBounds="true" />
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/shadoweffects" />
</FrameLayout>
drawable shadoweffects.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:angle="90"
android:endColor="#aa000000"
android:startColor="#00ffffff"
android:centerColor="#00ffffff" />
</shape>
根据要求更改颜色