android高度自适应
㈠ android ViewPager使用了height为wrap_content无效,希望自适应内容高度
ViewPager貌似是不能设置height包裹内容的,明磨亩你可激森以设置游毁height为0dp用weight来控制控件比例
㈡ 简单实现ImageView宽度填满屏幕,高度自适应的两种方式
方宏液法一:
<ImageView
android:id="@+id/zb_piclist_item_iamge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="@mipmap/ic_launcher"
android:visibility="卜衫gone"蔽弊物 />
//获取屏幕宽度
WindowManager m = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics outMetrics = new DisplayMetrics();
m.getDefaultDisplay().getMetrics(outMetrics);
//乘以2是因为左右两侧的宽度
//bobaoArcWidth bobaoArcHeight 原始图片宽高
int height = (int) (width / (Float.parseFloat(bobaoArcWidth)) * (Float.parseFloat(bobaoArcHeight)));
//设置图片参数
ViewGroup.LayoutParams layoutParams = viewHolder.zbPiclistItemIamge.getLayoutParams();
// layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
layoutParams.width = width;
layoutParams.height = height;
viewHolder.zbPiclistItemIamge.setLayoutParams(layoutParams);
方发二
public class ResizableImageView extends ImageView {
}
<LinearLayout
xmlns:android=" http://schemas.android.com/apk/res/android "
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</LinearLayout>
根据图片的宽度,高度,来按比例显示
final String app_arc_pic = list.get(position).ad_pic;
String adPicHeight = list.get(position).ad_pic_height;
String adPicWidth = list.get(position).ad_pic_width;
int adPicH = Integer.parseInt(adPicHeight);
int adPicW = Integer.parseInt(adPicWidth);
int width = activity.getWindowManager().getDefaultDisplay().getWidth();
㈢ Android 用自定义高度自适应的viewpager,在进行滑动的时候滑动很不顺畅,有时根本划不动,求大神帮忙下
自已重写ViewPager就行了在onMeasure里做一下处理就可以实现自适应高度了.
主要是重写onMeasure方法来实现的。源代码已上传附件。
㈣ 怎么修改gridview元素的高度自适应填满gridview-Android开发问答
在WEB程序的ASP页面中,山升敏都不建议使用该方法进行对数据的操作!为什么呢?那为什么现在极大多网站都没逗枝有采用你这种方式来进行数据操作呢?是别人没有想到?还是担心这样操作会对页面造成额外的开销?提主,你有想过这个问题吗?
我是见过有grid的网站中,是没有一个像你这样操作页面。通常都是获取当中一行的ID或可以获得对应数据的字段笑乎,再去查询一下数据库,再将数据返回到一个Table中对应的控件!
下面是一个简单的GRIDVIEW代码:
页面代码:
<div>
<asp:GridView ID="gvTest" runat="server">
<Columns>
<asp:BoundField DataField="customerID" Visible="False" />
<asp:BoundField DataField="customerName" HeaderText="名称" />
<asp:BoundField DataField="customerSex" HeaderText="性别" />
<asp:TemplateField HeaderText="操作">
<ItemTemplate>
<asp:LinkButton ID="lbtnUpdate" CommandArgument='<%# DataBinder.Eval(Container.DataItem,"customerID") %>'
runat="server" Text="Update" OnClick="lbtnUpdate_Click"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
<br />
<div>
<table align="center">
<tr>
<td>
名称:</td>
<td>
<asp:TextBox ID="txtCustName" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>
性别:</td>
<td>
<asp:TextBox ID="txtCustSex" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td colspan="2">
<asp:Button ID="btnUpdate" runat="server" Text="修改" Visible="false" OnClick="btnUpdate_Click" />
<asp:Button ID="btnCancel" runat="server" Text="取消" Visible="false" OnClick="btnCancel_Click" />
</td>
</tr>
</table>
</div>
<input type="hidden" id="txtCustID" runat="server" />
如下为后台代码:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGrid();
}
}
//绑定Grid
private void BindGrid()
{
string strCmd = "select * from CUSTOMERS";
//getDataSet函数通过一个SQL语句取得一个DataSet
DataSet ds = getDataSet(strCmd);
gvTest.DataSource = ds;
gvTest.DataBind();
}
//LinkButton事件,得到相关客户信息
protected void lbtnUpdate_Click(object sender, EventArgs e)
{
LinkButton lbtnTemp = sender as LinkButton;
//取得保存在LinkButton的CommandArgument的ID值.
string custID = lbtnTemp.CommandArgument;
txtCustID.Value = custID;
string strCmd = string.Format("select * from CUSTOMERS where customerID = {0}", custID);
DataSet ds = getDataSet(strCmd);
//通过ID查询出来的客户信息赋给对应的控件
txtCustName.Text = ds.Tables[0].Rows[0]["customerName"].ToString();
txtCustSex.Text = ds.Tables[0].Rows[0]["customerSex"].ToString();
//打开修改和取消按钮
btnCancel.Visible = true;
btnUpdate.Visible = true;
}
//修改
protected void btnUpdate_Click(object sender, EventArgs e)
{
string strCmd = "update CUSTOMERS set customerName='{0}',customerSex='{1}' where customerID={2}";
strCmd = string.Format(strCmd, txtCustName.Text, txtCustSex.Text, txtCustID.Value);
//ExecuteNon为执行修改的函数
int count = ExecuteNon(strCmd);
//屏蔽两个按钮
btnCancel.Visible = false;
btnUpdate.Visible = false;
}
//取消
protected void btnCancel_Click(object sender, EventArgs e)
{
//清空或还原Table中的控件
txtCustName.Text = "";
txtCustSex.Text = "";
btnCancel.Visible = false;
btnUpdate.Visible = false;
}
注:
上面代码中我没有写连接或Command什么的,我觉得你会这些了.再加上上面的代码只是带给你一种意识,供你参考!事例写得好潦草,只供参考,不推荐使用这样的编码方式!
㈤ Android如何实现屏幕分辨率的自适应
【答案】:最好可以通过权重(layout_weight)的方式来分配每个组件的大小,也可以通过具体的像素(dip)来确定大小。
尽量使用Relativelayout 。
已知应用支持平台设备的分辨率,可以提供多个layout_320*480 ...
drawable-hdpi,drawable-mdpi,drawable-ldpi分别代表分腊历御辨率为480*800,360*480,240*360, 放置图片大小相差1.5倍
最后还需要在AndroidManifest.xml里添加下面一段,没有这一段自适应就不能实现:
android:largeScreens="true"
android:normalScreens="true"
android:anyDensity = "true"/>
在标签和 标签之间添加上面那段代码。即可。
备注:三者的分辨率不一样,就像你把电脑的分烂肆辨率调低,图片会变轮岩大一样,反之分辨率高,图片缩小
还可以通过.9.png实现图片的自适应
㈥ android如何设置图片自适应控件大小
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/ic_launcher"/>
宽度和高度使用fill_parent (填充父窗体)
fill_parent 可以使控件充满父控件,也就是你说的自动使用图片控件外的控件大小。
㈦ android如何实现屏幕的自适应
在网页代码的头部内加入一行viewport元标签。
<meta大信name="viewport"content="width=device-width,initial-scale=1"/>
viewport的说明:
viewport是网页默认的宽度和高度,上面这行氏局代码的意思是,网页宽度默认等于屏幕宽度(width = device-width),原始缩放比例(initial-scale = 1)为1.0,即网页初始大小占屏幕面积的100%。所有主流浏览器都支持这个设置。
关于viewport的基本属性:
width=device-width :表示宽度是设备屏幕的宽度
initial-scale=1.0:表示初始的缩放比例
minimum-scale=0.5:表示最小的缩放比例
maximum-scale=2.0:表示最大的缩放比例
user-scalable=yes:表示用户是否可以调整缩滚核轮放比例
㈧ Android 自定义ViewGroup , 能够实现自适应高度。
检查下 ViewGroup 里面包含的元素
㈨ 在Android编程模式下,如何设置Button为自动适应
得到屏幕灶侍的高度h隐扒吵button。setheight(h/16)(此处还有其此槐他的方法自己去试一下)(此处的前提是button在垂直的线性布局中)
2. 通过 layoutparams 去设置 高度和宽度
㈩ android alertdialog 怎么设置高度自适应
WindowManager wm = getWindowManager();
Display display = wm.getDefaultDisplay();
android.view.WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();
lp.width = display.getWidth();
lp.height =LayoutParams.WRAP_CONTENT;
dialog.getWindow().setAttributes(lp);
任意拿陵取得任意局敏局桐让设置