❶ android布局文件設置TableLayout某一列寬度為屏幕寬度的30%
我給你一個思路吧:
<TableLayout
android:width=0dp;
android:weight=7;/>
<LinearLayout
android:width=0dp;
android:weight=3;/>
這樣就會有一個tablelayout和一個LinearLayout,tablelayout寬度占總寬度的30%,線性布局佔70%
權重做的,具體代碼這樣:
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TableRow
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@android:color/holo_orange_light" >
</TableRow>
<TableRow
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@android:color/background_light" >
</TableRow>
<TableRow
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:background="@android:color/darker_gray" >
</TableRow>
<TableRow
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@android:color/holo_blue_bright" >
</TableRow>
<TableRow
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@android:color/holo_green_dark" >
</TableRow>
<TableRow
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@android:color/holo_orange_dark" >
</TableRow>
<TableRow
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@android:color/holo_purple" >
</TableRow>
<TableRow
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@android:color/holo_red_dark" >
</TableRow>
</TableLayout>
實現的效果就是:
❷ 在安卓手機端 容器沒有定義固定寬, 使用viewport 後就縮成一半了
可能是你加的不對,參考我得寫法:
<metaname="viewport"content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
<metaname="apple-mobile-web-app-capable"content="yes"/>
<metaname="apple-mobile-web-app-status-bar-style"content="black-translucent"/>
<metaname="format-detection"content="telephone=yes"/>
<metaname="msapplication-tap-highlight"content="no"/>
你應該是做響應式布局的吧,這里有一篇響應式布局的示例,文章比較長不再全文貼出,參考:http://www.51xuediannao.com/html+css/htmlcssjq/704.html
❸ 不同版本的android如何控制對話框寬度
這個是屏幕適配的問題吧。
屏幕寬度不一樣,就算用dp,也不能達到好的效果。
如果想達到最佳的效果(比如dialog寬度大概占屏幕寬度的80%),用dp在不同的屏幕上是達不到預期的效果的。
其實有下面這樣方法可供參考:
設置match_parent或wrap_content這樣的,再設置一下邊距,每個屏幕上面都能看吧,如果dialog裡面沒有把寬度寫死的話。
獲取設備的寬高的像素,設置一個比值(如上面的80%),把設備的整個寬度,乘以這個比值,在代碼里動態進行配置。
如果要用dp來控制,那就建立多個不同的layout-XXX(如layout-lang,layout-ldpi)來適應不同的屏幕吧。
❹ Android TextView寬度和高度固定,怎麼根據顯示的字元串來計算出字體的尺寸
先獲取TextView的padding的值,然後用固定高度或寬度減去padding就是文字所佔的空間。
TextView tv = new TextView(this);
int top = tv.getPaddingTop();//有bottom,left,right,
int bottom = tv.getPaddingBottom();
假設固定高度為100,
那麼自體高度所佔空間應該是 100-(top+bottom)
❺ 怎麼限制textview的寬度
android中限制textview的寬度的方法有兩種:
1、使用maxlength限制輸入的長度
android:maxLines設置文本的最大顯示行數,與width或者layout_width結合使用,超出部分自動換行,超出行數將不顯示。
2、使用singleLine設置單行顯示,並設定layout_width
android:singleLine設置單行顯示。如果和layout_width一起使用,當文本不能全部顯示時,後面用「…」來表示。如android:text="test_singleLine"
❻ android 代碼里怎麼設置控制項的寬度
在對應的控制項中使用android:layout_width標簽即可。
android:layout_width標簽中可以使用match_parent常量使控制項尺寸與其上級組件尺寸相同
可以使用wrap_content使控制項尺寸剛好包裹住內容
也可以使用px(像素)、pt(磅)、dp(密度)、sp(可伸縮像素)作為單位,從而設置控制項的寬度:
例如:
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="one"
android:layout_gravity="right"/>
❼ android app 界面設計按什麼尺寸
android app 界面設計是按720*1280的,切圖上可以點9切圖做到所有手機的適配。
狀態欄、導航欄和主菜單欄,以720*1280的尺寸來設計,那麼狀態欄的高度應為50px,導航欄的高度96px,主菜單欄的高度96px,因為是開源的系統,這里的數值也只能作為參考。
Android為了區別於IOS,從4.0開始提出了一套HOLO的UI風格設計風格,鼓勵將底部的主菜單欄放到導航欄下面,從而避免點擊下方材料誤點虛擬按鍵,很多APP的新版中也採用了這一風格。
(7)android固定寬度擴展閱讀:
注意事項:
1、通常情況要定位一個Icon只需給出 上/下邊距,左/右邊距,標注圖標距離只需標到可點擊范圍外
通用型顏色、字體單獨標明一份,通用型模塊只需單獨標明一份,如導航欄。
2、手機可視區域通常為寬度固定,長度超出邊界可滑動,所以標注物體寬度時可按比例說明,如果要標注內容上下居中,左右居中,或等比可不標注。
3、當交付的是一張完整圖片時,不需做機型適配,只需給高清圖(1920*1080)即可,注意進行壓縮。
4、若圖標在不同頁面重復出現,且尺寸相差不大,直接給出最大一份切圖,並在圓形圖標明尺寸,程序會根據需求縮放。
5、當背景是純色時只需給出色值,Android使用16進制色值。
參考資料來源:網路-Android
參考資料來源:網路-界面設計
參考資料來源:網路-狀態欄
參考資料來源:網路-導航欄
參考資料來源:網路-開源系統
參考資料來源:網路-切圖
參考資料來源:網路-UI設計
❽ android 如何動態設置控制項的寬度和高度
一、方法
使用getLayoutParams() 和setLayoutParams()方法
二、示例代碼
LinearLayout.LayoutParams linearParams = (LinearLayout.LayoutParams) aaa.getLayoutParams();
// 取控制項aaa當前的布局參數
linearParams.height = 365; // 當控制項的高強制設成365象素
aaa.setLayoutParams(linearParams); // 使設置好的布局參數應用到控制項aaa
三、原理
a)getLayoutParams()和setLayoutParams()都是控制項基類view的public方法,在外部也可以直接調用。
b)由於LayoutParams一般是在加入容器中設置的,所以容易混淆所指定的布局屬性究竟是保存在容器中,還是控制項本身的屬性,答案是控制項本身。但是在設置時還是要注意布局屬性與容器種類密切相關。
❾ android ImageView設置寬度
<LinearLayoutxxxx
android:weightSum="2">
<ImageViewxxxx
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
</LinearLayout>
❿ android 動態設置布局寬度
例如設置一個圖片寬高 關鍵代碼:
//取控制項當前的布局參數
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) imageView.getLayoutParams();
//設置寬度值
params.width = dip2px(MainActivity.this, width);
//設置高度值
params.height = dip2px(MainActivity.this, height);
//使設置好的布局參數應用到控制項
imageView.setLayoutParams(params);
1
2
3
4
5
6
7
8
1
2
3
4
5
6
7
8
高度除了可以設置成以上固定的值,也可以設置成wrap_content或match_content
ViewGroup.LayoutParams.WRAP_CONTENT
ViewGroup.LayoutParams.MATCH_PARENT
1
2
1
2
在這里插入圖片描述
xml