android控件demo
❶ Android 手势缩放一个布局,布局里面有控件,跟随缩放,求demo
给出思路:
在代码中获得要旋转的布局;
监听布局的OnTouch事件;
当触发滑动事件后,创建一个旋转动画,将动画赋予布局;
布局中的控件注册自己的监听器,跟这个旋转没有影响。
这个是我想到的,没试验,题主可以试试。
有疑问,请追问。望采纳!
❷ Android 控件smartRefeshLayout只要下拉刷新,禁止上拉加载
一.导入依赖
在app-mole中添加RecycleView和SmartRefreshLayout的依赖
//recyclerview implementation 'com.android.support:recyclerview-v7:26.1.0' implementation 'com.android.support:design:26.1.0' //SmartRefreshLayout implementation 'com.scwang.smartrefresh:SmartRefreshLayout:1.0.4-7' implementation 'com.scwang.smartrefresh:SmartRefreshHeader:1.0.4-7'
二.在mainActivity中添加xml布局
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context="com.freshdemo.MainActivity"android:orientation="vertical"><com.scwang.smartrefresh.layout.SmartRefreshLayoutandroid:id="@+id/refreshLayout"android:layout_width="match_parent"android:layout_height="match_parent"app:srlAccentColor="#00000000"app:srlPrimaryColor="#00000000"app:srlEnablePreviewInEditMode="true"><android.support.v7.widget.RecyclerViewandroid:id="@+id/rv"android:layout_width="match_parent"android:layout_height="match_parent"/></com.scwang.smartrefresh.layout.SmartRefreshLayout></LinearLayout>
这是SmartRefreshLayout的基本布局,其中:
app:srlAccentColor="#00000000"//设置Header主题颜色 app:srlPrimaryColor="#00000000"//设置Footer主题颜色 app:srlEnablePreviewInEditMode="true"//开启和关闭预览功能
三.MainActivity中初始化和刷新加载事件
private RecyclerView mRecyclerView; private RefreshLayout mRefreshLayout; //初始化 mRecyclerView=findViewById(R.id.rv); mRefreshLayout = findViewById(R.id.refreshLayout); //刷新 mRefreshLayout.setOnRefreshListener(new OnRefreshListener() { @Override public void onRefresh(RefreshLayout refreshlayout) { mData.clear(); mNameAdapter.notifyDataSetChanged(); refreshlayout.finishRefresh(); } }); //加载更多 mRefreshLayout.setOnLoadmoreListener(new OnLoadmoreListener() { @Override public void onLoadmore(RefreshLayout refreshlayout) { for(int i=0;i<30;i++){ mData.add("小明"+i); } mNameAdapter.notifyDataSetChanged(); refreshlayout.finishLoadmore(); } });
四.运行效果
SmartRefreshLayout运行的默认效果如下
image.png
他们的包路径是:
com.scwang.smartrefresh.header.BezierCircleHeadercom.scwang.smartrefresh.header.DeliveryHeader//以下类似,在此省略//......
六.自定义Header和Footer
当然SmartRefreshLayout还支持自定义Header和Footer
具体可以参考官网中的自定义Header
SmartRefreshLayout关于属性这一块也是有很多可以设置的,大家依然可以去SmartRefreshLayout官网查看更多使用细则,这里就不展开讲解了
今天就讲到这里了,谢谢大家。
❸ android 动态加载控件,如何定义这个属性android:src="@drawable/demo"
在drawable-?/drawable
文件夹下创建demo.xml,或提供demo.jpg
即可取出值
❹ 求解:android中如何实现动态插入控件
直接给你上代码吧,写了我半个小时,经过了我的测试了的~
运行下就能看到结果了~关键的remove的时候有给你写注释~
布局的layout文件内容:
----------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:id="@+id/linearlayout">
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<Button android:layout_height="wrap_content" android:id="@+id/add"
android:text="Add" android:layout_width="100px"></Button>
<Button android:layout_height="wrap_content"
android:layout_width="100px" android:text="Remove" android:id="@+id/remove"></Button>
</LinearLayout>
<TextView android:id="@+id/TextView01" android:text="This is textView."
android:layout_width="fill_parent" android:gravity="center"
android:layout_height="50px"></TextView>
</LinearLayout>
----------------------------------------------------------------------------------
对应Activity的内容:
----------------------------------------------------------------------------------
package com.foxconn.dialog;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.LinearLayout;
public class DialogTest extends Activity implements OnClickListener {
private Button add_btn, remove_btn;
private LinearLayout linearLayout;
private int index = 0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
findViews();
register();
}
private void register() {
add_btn.setOnClickListener(this);
remove_btn.setOnClickListener(this);
}
private void findViews() {
add_btn = (Button) findViewById(R.id.add);
remove_btn = (Button) findViewById(R.id.remove);
linearLayout = (LinearLayout) findViewById(R.id.linearlayout);
}
protected View createView() {
Button btn = new Button(this);
btn.setId(index++);
btn.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
btn.setText("aaaaaa" + index);
return btn;
}
private void removeView() {
//获取linearlayout子view的个数
int count = linearLayout.getChildCount();
//研究整个LAYOUT布局,第0位的是含add和remove两个button的layout
//第count-1个是那个文字被置中的textview
//因此,在remove的时候,只能操作的是0<location<count-1这个范围的
//在执行每次remove时,我们从count-2的位置即textview上面的那个控件开始删除~
if (count - 2 > 0) {
//count-2>0用来判断当前linearlayout子view数多于2个,即还有我们点add增加的button
linearLayout.removeViewAt(count - 2);
}
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.add:
linearLayout.addView(createView(), 1);
break;
case R.id.remove:
removeView();
break;
default:
break;
}
}
}
----------------------------------------------------------------------------------
❺ 如何让android studio videoview 控件位置问题
给你看个布局,希望能帮到你。 这一般的界面布局大布局用的比较多的是相对布局,因为相对布局以后不用做屏幕适配,所有的控件都写在RelativeLayout里面,这个布局外面还有层ScrollView,带滚动的。其它的控件都可以参考上面的demo。
❻ android 中如何让控件一直在窗体底部
android让一个控件按钮居于底部的几种方法
1.采用linearlayout布局:
android:layout_height="0dp"<!--这里不能设置fill_parent-->
android:layout_weight="1"<!--这里设置layout_weight=1是最关键的,否则底部的LinearLayout无法到底部-->
2.采用relativelayout布局:
android:layout_alignParentBottom="true"<!--这里设置layout_alignParentBottom=true是最关键的,这个属性上级必须是RelativeLayout-->
3.采用fragment布局(activitygroup已经被弃用不建议使用)
=====================================
1.采用linearlayout布局:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/content"
android:layout_width="fill_parent"
android:layout_height="0dp"<!--这里不能设置fill_parent-->
android:layout_weight="1"<!--这里设置layout_weight=1是最关键的,否则底部的LinearLayout无法到底部-->
android:orientation="vertical">
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:orientation="vertical">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/runbackground"
android:focusable="false"/>
</LinearLayout>
</LinearLayout>
2.采用relativelayout布局:
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"<!--这里设置layout_alignParentBottom=true是最关键的,这个属性上级必须是RelativeLayout-->
android:orientation="vertical">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/runbackground"
android:focusable="false"/>
</LinearLayout>
</RelativeLayout>
3.采用fragment布局(activitygroup已经被弃用不建议使用)
<?xmlversion="1.0"encoding="utf-8"?>
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<fragmentclass="com.xu.fragment.FragmentDemoActivity$TitlesFragment"android:id="@+id/titles"android:layout_weight="1"
android:layout_width="0px"android:layout_height="match_parent"
/>
<FrameLayoutandroid:id="@+id/details"android:layout_weight="1"android:layout_width="0px"android:layout_height="match_parent"
android:background="?android:attr/detailsElementBackground"
></FrameLayout>
</LinearLayout>
==============================================
❼ 如何获取android安卓控件EditText中的内容
Android中Edit text控件的内容可以添加一个监听器,来获取内容放到别的控件上去,示例如下:
package nbe.sense7.vinci.edittext;
import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
public class EditTextDemoActivity extends Activity {
private EditText editText;
private TextView textView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
editText = (EditText)findViewById(R.id.input);
textView = (TextView)findViewById(R.id.output);
//设置EditText按键输入时的事件
editText.setOnKeyListener(new EditText.OnKeyListener(){
@Override
public boolean onKey(View arg0, int arg1, KeyEvent arg2) {
// TODO Auto-generated method stub
textView.setText(editText.getText());//获取edittext的内容
return false;
}
});
}
}
❽ android 根据后台数据动态添加控件,效果图如下:(哪位大神可以帮忙给个Demo(服务器+客户端),谢谢)
服务器返回json数组,android接收到数据使用JSONObject相关api处理
然后循环new button添加到ui指定的容器
❾ android 控件怎么传入dialogfragment中
在android开发中,时间控件是不可或缺的一部分,特别是在设置个人生日或按时间进行搜索时都要用到。
Android有内置的DatePicker和timePicker,使用起来也是相当的方便,既可以在布局中添加后findViewById调用,也可以直接在activity中重写onCreateDialog(int id)方法后调用showDialog(int id)弹出,现在网上关于android时间控件的demo也大都基于这两个控件的使用说明。但用过这两个控件的人都知道,这两个时间选择框有两个不太好的地方:
1、不是特别美观
2、时间控件生命周期不可控。如果想解决上面的问题,我们一般都会通过继承Dialog,写一个美观并且满足要求的时间控件。但这样花费的时间肯定比使用DatePicker和timePicker要多得多。
❿ Android中定义控件的时候看见了@ViewInject,请问这个是如何实现的呢最好给个demo,谢谢!!
依赖注入框架, 为了快速开发,网络 roboguice的用法,资料很多,就是利用反射原理将控件和事件绑定,节省你诸如 findViewById 这样的代码,写起来方便 。 优点: 开发速度快, 缺点: 对性能消耗略大。google官方不甚推荐。