LinearLayout下添加一个item

方式一:

定义一个线性布局:

向线性布局增加一个item:

cardPhotoListView.addView(new CardItemView(this),cardPhotoListView.getChildCount()-1);

自定义的视图

public class CardItemView extends LinearLayout {
	Button bt_delete;

	public CardItemView(Context context) {
		super(context);
		LayoutInflater.from(context).inflate(R.layout.userspecificinfor3_item,
				this);
	}

	public CardItemView(Context context, AttributeSet attrs) {
		super(context, attrs);
		LayoutInflater.from(context).inflate(R.layout.userspecificinfor3_item,
				this);
	}

}

方式二:

@ViewById(R.id.cardPhotoListView)LinearLayout cardPhotoListView;

@Click(R.id.addMaterial)
	public void addMaterial() {
		// TODO 动态增加一个线性布局
		view = View.inflate(this, R.layout.userspecificinfor3_item, null);
		cardPhotoListView.addView(view);
		runUiThread();
	}

@UiThread
	public void runUiThread() {
		scrollView.fullScroll(ScrollView.FOCUS_DOWN);
	}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要实现一个带有扫光效果的LinearLayout,可以按照以下步骤: 1. 在布局文件中添加LinearLayout,并设置其属性。 ```xml <LinearLayout android:id="@+id/linearLayout" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:background="@drawable/layout_bg"/> ``` 2. 在drawable文件夹中创建一个XML文件,设置LinearLayout的背景。这里可以使用渐变色来实现扫光效果。以下是一个示例代码: ```xml <shape xmlns:android="http://schemas.android.com/apk/res/android"> <gradient android:type="linear" android:startX="0" android:endX="100%" android:startY="0" android:endY="0" android:angle="45"> <item android:color="#00FFFFFF" android:offset="0" /> <item android:color="#FFFFFFFF" android:offset="0.5" /> <item android:color="#00FFFFFF" android:offset="1" /> </gradient> </shape> ``` 3. 在Activity中获取LinearLayout,并为其设置一个动画,使得渐变色的位置不断移动,从而实现扫光效果。 ```java LinearLayout linearLayout = findViewById(R.id.linearLayout); AnimationDrawable animation = new AnimationDrawable(); GradientDrawable drawable = (GradientDrawable) getResources().getDrawable(R.drawable.layout_bg); animation.addFrame(drawable, 500); drawable.setGradientCenter(0.0f, 0.0f); drawable.setGradientRadius(800); animation.setEnterFadeDuration(0); animation.setExitFadeDuration(500); animation.setOneShot(false); linearLayout.setBackgroundDrawable(animation); animation.start(); ``` 这里的AnimationDrawable是Android自带的一个动画类,可以用来实现帧动画效果。在这个例子中,我们将渐变色作为一帧,然后设置其不断移动的动画,从而实现扫光效果。 完成上述步骤后,就可以在应用中看到一个带有扫光效果的LinearLayout了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值