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官方不甚推薦。