當前位置:首頁 » 安卓系統 » android自適應寬度

android自適應寬度

發布時間: 2024-04-01 07:36:07

Ⅰ Android 自定義View 寬高總是充滿父容器,怎麼讓它自適應保持對應寬高

自定義View,想要自定義給定寬和高,你要寫自定義屬性,然後在xml文件中指定寬高才會有效,同時當給定的寬和高的值是wrap_content 或 fill_parent 這類的,這時需要在自定義View中重寫onMeasure方法,進行控制項的寬高測量。

Ⅱ android開發軟體如何做到自適應屏幕大小及不同解析度的手機

  1. 代碼中盡量不要設置控制項的寬高(盡量使用match_parent或者wrap_content)

  2. 即使某些時候要一定要設置控制項的大小,那也要用(控制項用dp,字體用sp)

  3. 圖片要分多套設計,mdpi里放320*480的;hdpi里放480*800的;xhdpi放720*1280的;xxhdpi里放1080*1920大小的

  4. 某些時間需要按屏幕大小平分的,使用android:layout_weight=""這個屬於來平分


不明白郵件我

Ⅲ 在Android寫一個表格如何自適應

網友們上網通常會採用800×600、1024×768兩種解析度,由於網頁不是用來給自己看的,所以我們必須讓自己的網頁能夠兼顧這兩種情況,讓不同解析度設置的網友都能夠看到一個排版美觀正確的網頁。
一、 自然拉伸
如果你的網站結構沒有用到大量的圖形來銜接,主要由表格來定結構,那麼你就可以使用該方法。非常適用於主要由表格、文字來表達信息的簡單的網頁頁面。製作表格時,只要你把表格的寬度屬性定義為100%
,表格就會根據解析度的不同自行調整寬度。
二、 固定居中

在800×600解析度下製作的網頁在1024×768解析度的機器上打開,整個網頁就會跑到左邊;1024×768解析度的網頁在800×600解析度的機器上有時也會變得"不堪入目"。兩種解析度各做一個吧?做起來費勁。所以目前普遍採用的方法是固定居中法!

現在大多數網民都還在用800*600的解析度,所以我們一般可以以此解析度為主。只要在網頁原代碼的<body>後緊加一句<center>,</body>前加一句</center>就OK了。不過有幾個問題這是要注意一下,第一個要注意的是上面說到的百分比的問題,表格、單元格的寬度單位最好要使用像素單位,而不要用百分比。例如width=770。如果你的表格寬度設的是百分比,那麼使用大於800×600的像素時,網頁就會拉寬,這樣網頁可能會變形。在<body>中加入leftmargin=0,即<body
leftmargin=0>這種情況下,800×600支持的表格寬度為780像素時不會出現滾動條。還有一點要注意的是不能用DW中的層來定位。
三、 兵分兩路
如果你的網頁不經常更新,而且對頁面效果極其在意,那好,你就設計兩個頁面,分別對應800×600和1024×768兩種解析度。然後根據不同的解析度進行跳轉就行了。

例如:

<script LANGUAGE="JavaScript">
function redirectPage() {
var
url_else =
var
url_800x600 =
var
url_1024x768 = ";
var url_1366x768
=
if ((screen.width ==
800) && (screen.height == 600))
window.location.href= url_800x600;
else if ((screen.width == 1024) &&

Ⅳ android中如何讓程序自適應屏幕大小

不同的android
target會有不同的大小,應用程序的界面需要針對不同的大小調整界面元素的尺寸。而且屏幕也可以在橫屏和豎屏之間切換,界面也需要調整。
默認情況下,當屏幕方面切換時,activity的oncreate()方法會被重新調用,所以可以在其中通過以下代碼來讀取屏的方向:
public
void
oncreate()
{
if(this.getresources().getconfiguration().orientation
==
configuration.orientation_landscape)
{
log.i("info",
"landscape");
}
else
if
(this.getresources().getconfiguration().orientation
==
configuration.orientation_portrait)
{
log.i("info",
"portrait");}}
如果在androidmanifest.xml中加入配置
android:configchanges="orientation|keyboardhidden|navigation
當屏幕翻轉時,activity就不會重復的調用oncreate()、onpause()和onresume().
而是調用onconfigurationchanged(configuration
newconfig)
int
screenwidth,screenheight;
windowmanager
windowmanager
=
getwindowmanager();
display
display
=
windowmanager.getdefaultdisplay();
screenwidth
=
display.getwidth();
screenheight
=
display.getheight();
也有人提到另一種方法:
displaymetrics
dm
=
new
displaymetrics();
getwindowmanager().getdefaultdisplay().getmetrics(dm);

Ⅳ android recyclerview 怎樣實現寬度隨item內容自適應

在ListView對象上設置setOnItemClickListener事件,實現onItemClick()方法,可以根據此方法的int類型參數,確定你所點擊的事哪個item。然後呢,通過LayoutInflater過濾野喚出你想要得到內容的控制項,然後通過控制項獲取氏脊彎值,殲悶例如:textView.getText().

Ⅵ AIR做的ANDROID游戲怎麼做到屏幕大小自適應

1.首先獲得手機屏幕的寬高,也就是你要顯示的范圍的大小
//豎屏
// private var screenWidth:int = stage.fullScreenWidth;
// private var screenHeight:int = stage.fullScreenHeight;

//橫屏
private var screenWidth:int = stage.fullScreenHeight;
private var screenHeight:int = stage.fullScreenWidth;

注意的是橫屏和豎屏寬高賦值要調轉

2.獲得1個長方形的顯示空間的對象

private var viewPort:Rectangle = new Rectangle(0, 0, screenWidth, screenHeight)

把要顯示的starling初始化時候把長方形對象插入到第三個參數
myStarling = new Starling(MainGame,stage,viewPort);

設置starling中要顯示畫面的大小
myStarling.stage.stageWidth = 480;
myStarling.stage.stageHeight = 320;

完成!

Ⅶ 簡單實現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 怎麼使用Bitmap+Canvas 自適應屏幕

ndroid 使用Bitmap+Canvas自適應屏幕方法如下:

1、首先得先獲取我們的手機屏幕的大小

3、這樣通過這個函數返回的Bitmap對象就是可以適應手機屏幕大小的了。。

Ⅸ android怎麼設置自適應大小的背景圖片

需要給你的ImageView布局加上Android:adjustViewBounds="true"

<ImageView android:id="@+id/test_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:adjustViewBounds="true"
android:layout_gravity="center"
android:contentDescription="@string/app_name"
android:src="@drawable/ic_launcher" />

然後,在代碼里設置ImageView.最大寬度和最大高度,因為adjustViewBounds屬性只有在設置了最大高度和最大寬度後才會起作用

int screenWidth = getScreenWidth(this);
ViewGroup.LayoutParams lp = testImage.getLayoutParams();
lp.width = screenWidth;
lp.height = LayoutParams.WRAP_CONTENT;
testImage.setLayoutParams(lp);

testImage.setMaxWidth(screenWidth);
testImage.setMaxHeight(screenWidth * 5); 這里其實可以根據需求而定,我這里測試為最大寬度的5倍

熱點內容
佛系源碼 發布:2024-05-07 14:04:03 瀏覽:672
php螞蟻 發布:2024-05-07 13:49:22 瀏覽:400
phpfpmpid 發布:2024-05-07 13:44:29 瀏覽:520
linuxtty1 發布:2024-05-07 13:40:10 瀏覽:864
linuxshell腳本中if 發布:2024-05-07 13:25:01 瀏覽:221
phpmysql擴展 發布:2024-05-07 13:25:01 瀏覽:800
星密碼開網店怎麼樣 發布:2024-05-07 13:23:26 瀏覽:354
安卓手機java模擬器 發布:2024-05-07 12:43:07 瀏覽:913
c語言java哪個好學 發布:2024-05-07 12:35:16 瀏覽:335
奧特曼訪問 發布:2024-05-07 12:34:38 瀏覽:894