现在UI设计瀑布流很火啊,貌似国内Android界,蘑菇街上是第一个尝试的。后来我又发现了一些地方也用到了,比如爱画报(http://aihuabao.cn),世纪佳缘。
其中后面两个是图文结合的,我觉得比较好。下面就是我在《爱画报》官网上截的图。
不多说,先上图,描述下我想做个什么样的效果。下面是网页上的效果,就是不单纯的是图片的堆积,而是在图片下面还带文字说明。
下面是截图,特意截了个美女,哈哈
貌似android业界蘑菇街最早用瀑布流效果,但感觉蘑菇街的瀑布流效果界面只有纯粹的图片效果,不好看。
于是我想在Android下也做出上面那样的效果。
我的思路是这样的:
1.自定义一个FallwView.
FallView布局:
最外层一个ScrollView
里层一个大LinearLayout, ll_main 里面的元素水平摆放
ll_main里面放三个LinearLayout,每个LinearLayout里面的元素又是水平摆放。
对于这个FlowView其实是想通过代码的方式动态设置里面的内容的 比如主LinearLayout里面有多少列子LinearLayout,不是固定写在xml里面的,
而是在代码里面动态addView进去。但还不知道怎么去实现。
2.自定义一个上面是图片下面是说明文字的MyImage的控件
准备好一些MyImage,然后循环addView进到每个LinearLayou中去。
能力有限,东拼西凑做出了下面这么个效果。
。
这实现的效果还很粗糙,大家一起来完善吧!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
下面贴出代码:
package com.tomyzhou.pull;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.ScrollView;
import android.widget.TextView;
public class FallDemoActivity extends Activity {
private ScrollView sv_main;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
sv_main = new ScrollView(this);
List<View> viewList = new ArrayList<View>();
for(int i = 0;i<60;i++){
if(i%2 == 0){
View view = View.inflate(this,R.layout.myimage,null);
ImageView iv_image = (ImageView) view.findViewById(R.id.iv_image);
iv_image.setImageResource(R.drawable.a1);
TextView tv_image = (TextView) view.findViewById(R.id.tv_image);
tv_image.setText("第"+i+"个图的描述");
viewList.add(view);
}if(i%2 == 1){
View view = View.inflate(this,R.layout.myimage,null);
ImageView iv_image = (ImageView) view.findViewById(R.id.iv_image);
iv_image.setImageResource(R.drawable.a14);
TextView tv_image = (TextView) view.findViewById(R.id.tv_image);
tv_image.setText("第"+i+"个图的描述");
viewList.add(view);
}
}
FallView fv = new FallView(this, viewList);
sv_main.addView(fv);
setContentView(sv_main);
}
}package com.tomyzhou.pull;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.Inflater;
import android.content.Context;
import android.graphics.Canvas;
import android.view.View;
import android.widget.LinearLayout;
//自定义瀑布流控件
public class FallView extends LinearLayout {
private List<LinearLayout> list;
private LinearLayout ll_list1;
private LinearLayout ll_list2;
private LinearLayout ll_list3; // 三列
/**
*
* @param context
* @param viewList
* 需要显示的图片列表
*/
public FallView(Context context, List<View> viewList) {
super(context);
list = new ArrayList<LinearLayout>();
View view = View.inflate(context, R.layout.layout_fall, this);
ll_list1 = (LinearLayout) view.findViewById(R.id.ll_list1);
ll_list2 = (LinearLayout) view.findViewById(R.id.ll_list2);
ll_list3 = (LinearLayout) view.findViewById(R.id.ll_list3);
initView(viewList);
}
// 添加每个LinearLayout里面的图片
/**
* @param number
* 每个LinearLayout里面Image的个数
*/
private void initView(List<View> viewList) {
System.out.println(viewList.size());
for (int i = 0; i < viewList.size(); i++) {
View view = viewList.get(i);
if (i % 3 == 0) {
ll_list1.addView(view);
}
if (i % 3 == 1) {
ll_list2.addView(view);
}
if (i % 3 == 2) {
ll_list3.addView(view);
}
}
}
}
package com.tomyzhou.pull;
import android.content.Context;
import android.view.View;
public class MyImage extends View{
public MyImage(Context context) {
super(context);
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ll_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<LinearLayout
android:id="@+id/ll_list1"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#aaaaaa"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:id="@+id/ll_list2"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#aaaaaa"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:id="@+id/ll_list3"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#aaaaaa"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
<?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="match_parent"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="@+id/iv_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="/blog_article/@drawable/a12/index.html" />
<TextView
android:id="@+id/tv_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textSize="14sp"
android:text="描述文字" />
</LinearLayout>
本来想把代码文件上传下来,却发现传不了附件。有需要的加Q吧:893434467,欢迎一起交流!
今天抽时间整理一下第三方的登陆与分享功能,主要包含新浪微博、腾讯微博、开心网、人人网、QQ空间的第三方登陆与分享以及实现QQ第三方登陆,下面来看下新浪微博的的第三方登陆与实现(另外,说明一点各大交友社区提供的SDK开发文档,可能会有更改,导致以前的SDK版本不能正常使用,但是使用SDK,开发的步骤都是大同小异的,只要掌握其SDK实现自己想要的功能就行了,一般来说比较常用的功能就属于第三方登陆与分享功能了):
第一步:下载SDK开发工具包以及相关文档1.进入到新浪微博官网: t.sina.com 点击页面最下方的开放平台,进入到开发者社区
进入如下页面,依次点击文档——>资源下载-——>SDK下载——>Android SDK
进入以下页面:
进入选择SDK下载页面,
进入下载页面如果是在Windows下选择zip格式的,在Linux下选择tar.gz的,下载完成后解压压缩文件
weibo_android_sdk-master文件夹中会有以下项目文件:
其中以.demo结尾的都是使用SDK开发的一些实例,我们先用这些Demo来实现我们第三方登陆与实现分享功能,
我们把以上项目导入到我们的Eclipse中。
第二步:创建自己的应用
进入如下页面:
进入创建应用页面:
应用创建成功后,进入页面
找到App Key App Secret这是开发必用的!点击高级信息:
在此页面,回调页面设置,此回调页面必须设置,马上在导入的项目中会用到!先记下此处,至关重要!
第三步:开始进行开发:我们将刚刚下载好的·SDK中的实例项目导入到Eclipse中项目目录结构如下所示:
编辑MainActivity.java中的内容:
将 CONSUMER_KEY 替换为自己新建应用的App Key
将 刚刚需要设置回调页面的地方设置 为 :"http://www.sina.com" 即:
到此差不多可以了,我们运行下项目:
注意以上 access_token 以下们进行的各种操作都离不开它,就像一个通行证可以畅通无阻的访问自己以及自己关注的好友的微博信息,以及发送微博都离不开access_token
我们点击微博功能演示——>发送微博 进入以下界面:
发送微博,我们进入到新浪微博,官方主页查看自己的微博:
此为,分享的简单实现!
第四步:第三方登陆的实现经过以上三步,可以进入到SDK自带的分享界面进行分享,同时,我们也已经实现了第三方登陆,我们需要获得新浪微博上面的信息,我们就需要用到access_token令牌,使用令牌可以获得个人资料,调用发微博接口等等!下面,我们来看如何获取个人资料!
打开APITypeListActivity.java 将登录用户的Uid传进来就可以,查看当前登录用户的个人信息以及最近发布的几条微博!
项目下载地址:http://download.csdn.net/detail/qq435757399/4779056
C字符串与NSString之间的转换
代码:
const char *cString = "这是一个C字符串, c string";
NSString *nsstring = @"这是个NSString字符串, nsstring";
NSLog(@"cString字符串-->%s ",cString);
NSLog(@"NSString字符串-->%@",nsstring);
const char *cString2 = [nsstring UTF8String];
NSString *nsstring2 = [NSString stringWithUTF8String:cString];
NSLog(@"cString2字符串-->%s ",cString2);
NSLog(@"NSString2字符串-->%@",nsstring2);结果:
char类型的C字符串中文在Mac系统下打印出来显示乱码,这种乱码并不是错误,是ASCII解码所导致的。